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

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

解决办法如下:

找到webpack.config.js文件:

01var webpack = require('webpack');
02var path = require('path');
03 
04module.exports = {
05  // entry: './js/entry.js',
06  entry: [
07    'webpack-dev-server/client?http://127.0.0.1:3000', // WebpackDevServer host and port
08    'webpack/hot/only-dev-server',
09    './js/index.js' // Your app entry point
10  ],
11  output: {
12    path: __dirname + '/js/',
13    filename: 'bundle.js',//定义热插拔文件名字
14    publicPath: '/js/'
15  },
16  module: {
17    loaders: [
18      { test: /\.css$/, loader: 'style!css' },
19      { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'},
20      //{ test: /\.jsx?$/, loaders: ['react-hot', 'babel'], exclude:'/node_modules/' }
21      { test: /\.jsx?$/, loaders: ['react-hot', 'babel'], include: path.join(__dirname, 'src') }
22    ]
23  },
24  resolve: {
25    extensions: ['', '.js', '.jsx']
26  },
27    postLoaders: [
28        {test: /intents\//, loader: 'webworker'},
29        {test: /components\//, loader: 'react-hot', except: /node_modules/}
30    ]
31},
32plugins: [
33    new webpack.NoErrorsPlugin(),
34    new webpack.DefinePlugin({//添加此块代码
35        'process.env.NODE_ENV': '"development"'
36    }),
37    new webpack.ContextReplacementPlugin(
38        /transitions\//,
39        path.join(__dirname, "webapp")
40    ),
41    new webpack.ContextReplacementPlugin(
42        /intents\//,
43        path.join(__dirname, "webapp")
44    )
45]

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

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