[英]Webpack: how to use CommonsChunkPlugin with multiple splitted bundles
I have two independent parts of application that both splitted to 'app' and 'vendor' bundles. 我有两个独立的应用程序部分,都分为“ app”和“ vendor”捆绑包。
Webpack entries: Webpack条目:
entry: {
'client-app': path.join(BASE_DIR, 'front-end-sources', 'client', 'scripts', 'main.ls'),
'client-vendor': path.join(BASE_DIR, 'front-end-sources', 'client', 'scripts', 'vendor.ls'),
'admin-app': path.join(BASE_DIR, 'front-end-sources', 'admin', 'scripts', 'main.ls'),
'admin-vendor': path.join(BASE_DIR, 'front-end-sources', 'admin', 'scripts', 'vendor.ls')
},
And plugins: 和插件:
plugins: [
new ExtractTextPlugin('[name].bundle.css'),
new webpack.optimize.CommonsChunkPlugin({
names: ['client-app', 'client-vendor'],
minChunks: Infinity
}),
new webpack.optimize.CommonsChunkPlugin({
names: ['admin-app', 'admin-vendor'],
minChunks: Infinity
})
]
With just 'client-app' and 'client-vendor' or 'admin-app' and 'admin-vendor' and single CommonsChunkPlugin it works perfect, it generates 2 bundles (app & vendor) but with this pairs it fails with error: 仅使用'client-app'和'client-vendor'或'admin-app'和'admin-vendor'以及单个CommonsChunkPlugin,它可以完美地工作,它会生成2个捆绑包(应用程序和供应商),但是使用此对,它会失败并出现错误:
ERROR in CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (admin-app)
ERROR in CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk (admin-vendor)
How I can do it right? 我该怎么办?
I had the same requirement and solved it by splitting the config into two and supplying module.exports with an array. 我有相同的要求,并通过将配置分为两部分并为array.exports提供数组来解决了该问题。
module.exports = [{
entry: {
'client-app': path.join(BASE_DIR, 'front-end-sources', 'client', 'scripts', 'main.ls'),
'client-vendor': path.join(BASE_DIR, 'front-end-sources', 'client', 'scripts', 'vendor.ls')
},
...
plugins: [
new ExtractTextPlugin('[name].bundle.css'),
new webpack.optimize.CommonsChunkPlugin({
names: ['client-app', 'client-vendor'],
minChunks: Infinity
})
]
},
{
entry: {
'admin-app': path.join(BASE_DIR, 'front-end-sources', 'admin', 'scripts', 'main.ls'),
'admin-vendor': path.join(BASE_DIR, 'front-end-sources', 'admin', 'scripts', 'vendor.ls')
},
...
plugins: [
new ExtractTextPlugin('[name].bundle.css'),
new webpack.optimize.CommonsChunkPlugin({
names: ['admin-app', 'admin-vendor'],
minChunks: Infinity
})
]
}]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.