-
-
Save njzydark/682b2b56c2b6c927f274d50c097d4196 to your computer and use it in GitHub Desktop.
Per-page split chunks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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