CommonsChunkPlugin doesn’t recognize common chunks in split points

It seems like the CommonsChunkPlugin only works with gathering common code from entry points, but ignores split points as being sources of common code.

Example:

We have an app with this graph:

App – has a require.ensure for B and C
B – requires jquery
C – requires jquery

In webpack.config, we have 1 entrypoint, App. We also use the CommonsChunkPlugin:

new webpack.optimize.CommonsChunkPlugin({
filename: “common.bundle.js”,
minChunks: 2
})

Expected:
common.bundle.js includes jquery
B and C split point bundles do not have jquery

Resulted:
common.bundle.js has nothing
B and C BOTH have redundant copies of jquery

As a workaround, if I make B and C entry points in the config, the plugin works as expected. But we don’t need B and C as entry points, they are split points.

Author: Fantashit

1 thought on “CommonsChunkPlugin doesn’t recognize common chunks in split points

Comments are closed.