Webpack splitchunks creates dynamic chunk file

92 Views Asked by At

expecting to have only two chunks vendors and commons. However webpack creates a new chunk file for specific entries with delimiter.

optimization: {
    splitChunks: {
        chunks: 'all',
        cacheGroups: {
            vendor: {
                name: 'vendors',
                chunks: 'all',
                test: /[\\/]node_modules[\\/]/,
                reuseExistingChunk: true,
            },
            common: {
                chunks: 'all',
                minChunks: 9,
                name: 'commons',
                reuseExistingChunk: true,
            }
        }
    }
}

How to force webpack to use one of those in cacheGroups and not to create a new one?

1

There are 1 best solutions below

0
rohanc On

After upgrading from Webpack v4 to v5 I had a similar problem. There were a couple of chunks with "~" in their filename.

This splitChunks configuration got me back to only one bundle file per entrypoint, and one shared vendor bundle.

optimization: {
    splitChunks: {
       cacheGroups: {
          commons: {
             test: /[\\/]node_modules[\\/]/,
             name: "vendor",
             chunks: "initial",
          },
       }
    }
}