我看到的所有例子在进行热模块替换时,都是将条目作为字符串数组。
如果你有多个条目,它是如何工作的呢?我尝试了下面的方法,但仍然得到了“未捕获的异常:HMR被禁用”的消息。
Webpack配置:
module.exports = {
context: path.join(staticPath, "js"),
entry: {
hot: 'webpack/hot/only-dev-server',
main: './main.js',
admin: './admin.js',
vendor: './vendor.js',
devServerClient: 'webpack-dev-server/client?http://localhost:4000'
},
output: {
filename: "[name].bundle.js",
path: path.join(staticPath, "js/"),
publicPath: "http://localhost:4000/static/bundles/"
},
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loaders: ["react-hot", "babel-loader"] },
{ test: /\.json$/, loader: "json" }
]
},
resolve: {
extensions: ['', '.js', '.json']
},
plugins: [
new webpack.optimize.CommonsChunkPlugin('shared', 'shared.bundle.js'),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new BundleTracker({ path: rootPath, filename: './webpack-stats.json' })
]
}