Webpack+React+Hot控制台报错:Cannot read property ‘NODE_ENV’ of undefined

分类:Javascript| 发布:佚名| 查看: | 发表时间:2016/2/16

解决办法如下:

找到webpack.config.js文件:

var webpack = require('webpack');
var path = require('path');

module.exports = {
// entry: './js/entry.js',
entry: [
'webpack-dev-server/client?http://127.0.0.1:3000', // WebpackDevServer host and port
'webpack/hot/only-dev-server',
'./js/index.js' // Your app entry point
],
output: {
path: __dirname + '/js/',
filename: 'bundle.js',//定义热插拔文件名字
publicPath: '/js/'
},
module: {
loaders: [
{ test: /\.css$/, loader: 'style!css' },
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'},
//{ test: /\.jsx?$/, loaders: ['react-hot', 'babel'], exclude:'/node_modules/' }
{ test: /\.jsx?$/, loaders: ['react-hot', 'babel'], include: path.join(__dirname, 'src') }
]
},
resolve: {
extensions: ['', '.js', '.jsx']
},
postLoaders: [
{test: /intents\//, loader: 'webworker'},
{test: /components\//, loader: 'react-hot', except: /node_modules/}
]
},
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({//添加此块代码
'process.env.NODE_ENV': '"development"'
}),
new webpack.ContextReplacementPlugin(
/transitions\//,
path.join(__dirname, "webapp")
),
new webpack.ContextReplacementPlugin(
/intents\//,
path.join(__dirname, "webapp")
)
]

注意'"不能直接写字符串,要字符串外再包装一层。
也可以这么写:

new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
365据说看到好文章不转的人,服务器容易宕机
原创文章如转载,请注明:转载自郑州网建-前端开发 http://camnpr.com/
本文链接:http://camnpr.com/javascript/2245.html