Skip to content

Instantly share code, notes, and snippets.

@Akryum
Created September 27, 2018 10:18
Show Gist options
  • Save Akryum/ece2ca512a1f40d70a1d467566783219 to your computer and use it in GitHub Desktop.
Save Akryum/ece2ca512a1f40d70a1d467566783219 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