I'm trying to migrate to webpack4 from 3 and I'm having a really hard time migrating CommonsChunkPlugin
.
On WP3, I have the following simplified configuration:
const entries = {
client: './src/index.js',
common1: ['lodash'],
common2: ['react', 'react-dom']
};
module.exports = {
...
entry: entries,
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: ['common1', 'common2'],
minChunks: Infinity
})
]
};
On WP4 I've already tried multiple combinations using optimization.splitChunks but I just can't get it to properly bundle my modules in a way that they are sharing common dependencies, like it used to be on WP3.
Here is what I used on my last try, but the final bundles are much bigger in size:
// same entries object
const entries = { ... };
module.exports = {
...
entry: entries,
optimization: {
splitChunks: {
minChunks: Infinity,
chunks: 'initial',
cacheGroups: {
common1: { test: 'common1' },
common2: { test: 'common2' },
// disables the default definition of these cache groups
vendors: false,
default: false
}
}
};