解决办法如下:
找到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')
}),