i follow this topic Build the app in multi-page mode in Vue Cli doc, it working fine but i realize that there is only 1 vendor file instead of 2 (per page entry).
How can i split vendor file? i don't want to have one unnecessary big vendor file shared across many page entries. (i want to have it in single app).
For screenshot above, i want to have one vendor file for index.xxx.js and one for report.xxx.js
Please suggest, Thank you
module.exports = {
pages: {
index: {
entry: 'src/monitor/main.js',
template: 'public/index.html',
chunks: ['chunk-common', 'chunk-index-vendors', 'index']
},
report: {
entry: 'src/report/main.js',
chunks: ['chunk-common', 'chunk-report-vendors', 'report']
}
},
chainWebpack: config => {
const options = module.exports
const pages = options.pages
const pageKeys = Object.keys(pages)
// Long-term caching
const IS_VENDOR = /[\\/]node_modules[\\/]/
config.optimization
.splitChunks({
cacheGroups: {
...pageKeys.map(key => ({
name: `chunk-${key}-vendors`,
priority: -11,
chunks: chunk => chunk.name === key,
test: IS_VENDOR,
enforce: true,
})),
common: {
name: 'chunk-common',
priority: -20,
chunks: 'initial',
minChunks: 2,
reuseExistingChunk: true,
enforce: true,
},
},
})
}
}
It's based on the GitHub thread: https://github.com/vuejs/vue-cli/issues/2381#issuecomment-425038367
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With