New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can CommonsChunkPlugin add `excludes` support? #1943

Closed
chemdemo opened this Issue Jan 28, 2016 · 4 comments

Comments

Projects
None yet
5 participants
@chemdemo

chemdemo commented Jan 28, 2016

Below is my webpack config:

{
    entry: {
        a: './src/app/a.jsx',
        b: './src/app/b.jsx',
        vendor: ['react', 'react-dom']
    },
    plugins: [
        new CommonsChunkPlugin({
            name: 'common',
            chunks: ['a', 'b']
        })
    ]
}

a and b chunk required 3rd component foo, foo relies on react.

now i expect output 4 files: a.js, b.js, vendor.js(only include react and react-dom lib), common.js(include modules which a and b required but excludes react and react-dom), but the built result is:

chunk    {0} a.js (a) 2.56 kB {3} [rendered]
    [0] multi a 28 bytes {0} [built]
    [1] ./src/app/a.jsx 601 bytes {0} [built]
   [11] ./src/scss/a.scss 1.16 kB {0} [built]
   [12] ./~/css-loader?sourceMap&modules&localIdentName=[local]!./~/sass-loader!./src/scss/a.scss 700 bytes {0} [built]
   [13] ./src/img/flymeos.png 70 bytes {0} [built]
chunk    {1} b.js (b) 2.32 kB {3} [rendered]
    [0] multi b 28 bytes {1} [built]
   [14] ./src/app/b.jsx 601 bytes {1} [built]
   [15] ./src/scss/b.scss 1.16 kB {1} [built]
   [16] ./~/css-loader?sourceMap&modules&localIdentName=[local]!./~/sass-loader!./src/scss/b.scss 532 bytes {1} [built]
chunk    {2} vendor.js (vendor) 580 kB [rendered]
    [0] multi vendor 40 bytes {2} [built]
    [2] ./~/react/dist/react.js 579 kB {2} {3} [built]
    [3] ./~/react-dom/dist/react-dom.js 1.55 kB {2} {3} [built]
chunk    {3} common.js (common) 594 kB [rendered]
    [2] ./~/react/dist/react.js 579 kB {2} {3} [built]
    [3] ./~/react-dom/dist/react-dom.js 1.55 kB {2} {3} [built]
    [4] ./src/components/foo/index.jsx 710 bytes {3} [built]
    [5] ./src/components/foo/index.scss 1.19 kB {3} [built]
    [6] ./~/css-loader?sourceMap&modules&localIdentName=[local]!./~/sass-loader!./src/components/foo/index.scss 706 bytes {3} [built]
    [7] ./~/css-loader/lib/css-base.js 1.48 kB {3} [built]
    [8] ./~/style-loader/addStyles.js 6.09 kB {3} [built]
    [9] ./src/scss/base.scss 1.17 kB {3} [built]

the react and react-dom lib had built twice now.

but i don't except to use <script> to link this 2 files in html because i had use html-webpack-plugin to auto build html file.

so, is it possible the CommonsChunkPlugin plugin add excludes argument to exclude some files from the output common files?

@sokra

This comment has been minimized.

Show comment
Hide comment
@sokra

sokra Jan 28, 2016

Member

You never connected the vendor chunk with the remaining chunks. What you need to do is add the vendor chunk as parent of the common chunk.

// add common as parent of a and b
new CommonsChunkPlugin({ 
  name: 'common',
  chunks: ['a', 'b']
}),
// add vendor as parent of common
new CommonsChunkPlugin({
  name: 'vendor',
  chunks: ['common'] // could be omitted as it is the default
}),

or shorter: (equivalent)

new CommonsChunkPlugin({ 
  names: ['common', 'vendor']
}),

https://github.com/webpack/webpack/tree/master/examples/two-explicit-vendor-chunks

Member

sokra commented Jan 28, 2016

You never connected the vendor chunk with the remaining chunks. What you need to do is add the vendor chunk as parent of the common chunk.

// add common as parent of a and b
new CommonsChunkPlugin({ 
  name: 'common',
  chunks: ['a', 'b']
}),
// add vendor as parent of common
new CommonsChunkPlugin({
  name: 'vendor',
  chunks: ['common'] // could be omitted as it is the default
}),

or shorter: (equivalent)

new CommonsChunkPlugin({ 
  names: ['common', 'vendor']
}),

https://github.com/webpack/webpack/tree/master/examples/two-explicit-vendor-chunks

@chemdemo

This comment has been minimized.

Show comment
Hide comment
@chemdemo

chemdemo Jan 28, 2016

year, it works! thanks very much!!

chemdemo commented Jan 28, 2016

year, it works! thanks very much!!

@chemdemo chemdemo closed this Jan 28, 2016

@ashsidhu

This comment has been minimized.

Show comment
Hide comment
@ashsidhu

ashsidhu May 20, 2016

Worked for me as well. Thanks

ashsidhu commented May 20, 2016

Worked for me as well. Thanks

@zhang-xiao

This comment has been minimized.

Show comment
Hide comment
@zhang-xiao

zhang-xiao May 10, 2017

Thanks a lot:)

zhang-xiao commented May 10, 2017

Thanks a lot:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment