我正在使用 webpack 4 splitchunk 导出 js 文件,我的应用程序有 4 个条目:
entry : {
bg : './src/background-scripts/' ,
content : ['./src/content-scripts/firefox-fix.js', './src/content-scripts/'] ,
options : [
'./src/options/'
],
popup : './src/popup/' ,
'bs-lite' : './src/public/bootstrap-lite.scss'
} ,
我想将popup
和content
条目打包到common1.js
. 然后我像这样配置splitchunk:
optimization: {
splitChunks: {
cacheGroups: {
commons1: {
name: 'commons1.js',
test: module => {
for (const chunk of module.chunksIterable) {
if (chunk.name && /(popup|content)/.test(chunk.name)) {
if (module.nameForCondition() && /[\\/]node_modules[\\/]/.test(module.nameForCondition())) {
return true;
}
}
}
return false;
},
minChunks: 1,
chunks: 'all'
},
commons2: {
name: 'commons2.js',
chunks(chunk){
return chunk.name === 'commons1.js' || chunk.name === 'options'
},
minChunks: 1,
chunks: 'all'
},
commons3: {
name: 'commons3.js',
chunks(chunk){
return chunk.name === 'bg' || chunk.name === 'commons2.js'
},
minChunks: 1,
chunks: 'all'
},
}
}
},
但是当我运行这个配置时,显示如下错误:
/Users/source/frontend/c/build/webpack.base.config.js:61
if (module.nameForCondition() && /[\\/]node_modules[\\/]/.test(module.nameForCondition())) {
^
TypeError: module.nameForCondition is not a function
我从互联网上搜索似乎没有人面临这个问题。我该怎么做才能解决它?