我正在开发一个google chrome扩展程序,当我使用较低版本的webpack时,我用这样的方式来配置代码块:
plugins : [
new CommonsChunkPlugin( {
name : 'commons1',
filename : 'commons1.js' ,
allChunks: true,
chunks : [ 'popup','content' ],
chunksSortMode: 'manual',
}) ,
new CommonsChunkPlugin({
name: 'commons2',
filename :'commons2.js' ,
allChunks: true,
chunks : [ 'commons1.js' , 'options' ]
}) ,
new CommonsChunkPlugin({
name: 'commons3',
filename :'commons3.js' ,
allChunks: true,
chunks : [ 'bg' , 'commons2.js' ]
}) ,
new ExtractTextPlugin( '[name].css' )
]在完成webpack 5旅之后,他们删除了CommonsChunkPlugin并使用了splitChunks,我读了splitChunks文档,不知道如何将我的旧配置迁移到新的splitChunks。是否可以将旧配置迁移到新的splitChunks?使用splitChunks编写连续化的平等方式是什么?
发布于 2022-01-17 04:13:50
在splitChunk中,我是这样写的:
optimization: {
splitChunks: {
cacheGroups: {
commons1: {
name: 'commons1',
chunks: 'all',
minChunks: 1,
test(module,chunks){
for (const chunk of module.chunksIterable) {
if (chunk.name && /(popup|content)/.test(chunk.name)) {
return true;
}
}
return false;
}
},
commons2: {
name: 'commons2',
chunks: 'all',
minChunks: 1,
test(module,chunks){
for (const chunk of module.chunksIterable) {
if (chunk.name && /(options|commons1)/.test(chunk.name)) {
return true;
}
}
return false;
}
},
commons3: {
name: 'commons3',
chunks: 'all',
minChunks: 1,
test(module,chunks){
for (const chunk of module.chunksIterable) {
if (chunk.name && /(bg|commons2)/.test(chunk.name)) {
return true;
}
}
return false;
}
},
}
}
},https://stackoverflow.com/questions/70722619
复制相似问题