I am using webpack 4 splitchunk to export the js file, my app have 4 entry:
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'
} ,
I want to package the popup and content entry to common1.js. then I config the splitchunk like this:
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'
},
}
}
},
But when I run this config, shows error like this:
/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
I am searching from internet seems no one facing this problem. what should I do to fix it?