我正在使用带有webpack的react-hot插件,并且在我遵循指示后它可以工作:
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:8090',
'webpack/hot/only-dev-server',
'./src/index'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
}]
}
};
生成的/static/bundle.js
包含所有库。
虽然我想从我的应用程序中拆分供应商,但我尝试添加多个入口点:
module.exports = {
entry: {
app: ['./src/index'],
vendor: [
'webpack-dev-server/client?http://localhost:8090',
'webpack/hot/only-dev-server'
]
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
}]
}
};
然而/static/app.bundle.js仍然包含jquery,react...
。
这可能吗?
更新这是配置,在@zerkms提到供应商必须明确声明后,可以按预期工作:
module.exports = {
entry: {
app: ['./src/index'],
vendor: [
'webpack-dev-server/client?http://localhost:8090',
'webpack/hot/only-dev-server', 'react', 'jquery'
]
},
output: {
path: path.join(__dirname, 'dist'),
filename: 'app.bundle.js',
publicPath: '/static/'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.bundle.js')
],
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot', 'babel'],
include: path.join(__dirname, 'src')
}]
}
};