CommonsChunkPlugin does not move shared class

Do you want to request a feature or report a bug?

What is the current behavior?

Class hierarchy

            Main (entry, common chunk)
           /    \
     ClassA      ClassB
       \          \
        \          ClassC
         \         /

Main require ClassA and ClassB using require.ensure().
ClassB require ClassC using require.ensure().
ClassA and ClassC require ReusableComponent using simple require().

Finaly webpack emits following chunks:

  • 0.js – contains ClassA, ReusableComponent
  • 1.js – contains ClassB
  • 2.js – contains ClassC, ReusableComponent
  • main.js – contains Main class


I try to configure CommonsChunkPlugin to move ReusableClass to main chunk in order to remove code duplication.

new webpack.optimize.CommonsChunkPlugin({
            name: 'main',
            minChunks: 2,
            children: true

And webpack does not do this.

If the current behavior is a bug, please provide the steps to reproduce.

What is the expected behavior?
ReusableCompoent class has to move to chunk main.

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
Node.js 7.2.1
Windows 10

Author: Fantashit

2 thoughts on “CommonsChunkPlugin does not move shared class

  1. It’s expected this way, as children: true only affects direct children of the chunk and the chunk with ClassC is not a direct child of main.

    Maybe it makes sense to add a recursive mode to grab also modules from indirect children.

Comments are closed.