Skip to content

Instantly share code, notes, and snippets.

@njzydark
Forked from Akryum/vue.config.js
Created October 21, 2020 10:06
Show Gist options
  • Save njzydark/682b2b56c2b6c927f274d50c097d4196 to your computer and use it in GitHub Desktop.
Save njzydark/682b2b56c2b6c927f274d50c097d4196 to your computer and use it in GitHub Desktop.
Per-page split chunks
module.exports = {
pages: {
pageA: 'src/pageA.js',
pageB: 'src/pageB.js',
pageC: 'src/pageC.js',
},
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: {
vendors: {
name: 'chunk-vendors',
priority: -10,
chunks: 'initial',
minChunks: 2,
test: IS_VENDOR,
enforce: true,
},
...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,
},
},
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment