I’ve got a seemingly pretty straightforward Webpack code splitting setup that I’m having trouble migrating to Webpack 4. I have two entries, called main
and preview
. I want to do an initial code split into a vendor
chunk for the vendor modules in main
, but I want to keep preview
as a single chunk.
Relevant part of the working configuration in Webpack 3:
{
entry: {
main: './src/application.js',
preview: './src/preview.js',
},
plugins: [{
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['main'],
minChunks({context}) {
if (!context) {
return false;
}
const isNodeModule = context.indexOf('node_modules') !== -1;
return isNodeModule;
},
}),
}]
}
Specifically, using the chunks
property in the CommonsChunkPlugin
options allows me to do what I need to do easily. Is there an equivalent in Webpack 4’s optimization.splitChunks
configuration?
preview
bundle to totally self-contained, so it sounds like I will need to configure a higher-prioritycacheGroup
for it. However, I’d still like for dependencies used in bothpreview
andmain
to be split into thevendor
chunk formain
’s purposes. Is that possible? – Spiky