Skip to content

Code chunking(vendor): difference in sizes #5057

Closed
@aseem2625

Description

@aseem2625

Do you want to request a feature or report a bug?
Report confusion from documentation

What is the current behavior?
I'm following the link https://webpack.js.org/guides/code-splitting-libraries/
The link says that both of below are same in achieving results:

Block 1:

new webpack.optimize.CommonsChunkPlugin({
    names: ['vendor', 'manifest'] // Specify the common bundle's name.
})

and

Block 2:

  new webpack.optimize.CommonsChunkPlugin({
    name:'vendor',
    minChunks: function (module) {
      return module.context && module.context.indexOf('node_modules') !== -1; // Yes, my dependencies are in the `node_modules` directory only
    }
  }),
  new webpack.optimize.CommonsChunkPlugin({
    name: 'manifest' 
 }),

However, the results are different.
The 2nd code is further decreasing the size of bundle.js but increasing size of vendor.js as compared to 1st code.

What is the expected behavior?
Both should give same results as per the link, isn't it?

All below are minified by ungzipped

367K merchant_f635dfc7bac94b0ce269.js
797K vendor_4ecf8f4402fec3b30e21.js

Note: The above is with just with

  new webpack.optimize.CommonsChunkPlugin({
    name: 'vendor',
  }),

Block 1:

367K merchant_fdeaaf746c5086d62004.js
795K vendor_58f5a6e9a4b78c27541f.js

Block 2:

341K merchant_74101a326fd4fcb817ee.js
837K vendor_fc23737da683023356a5.js

Tested with 3 different repositories (2 react repos and 1 infernojs repo). Similar observations.

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

Node: 4.8.0
Webpack: 2.5.1
OSX

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions