Alan Alan - 3 months ago 52
Javascript Question

Webpack CommonsChunkPlugin not working as expected

Folder Structure:
Project Folder Structure

app.js, benchmark.js, board.js all require jquery. I just want to extract jquery as vender.js and three other bundles only contain application code:

Webpack Config:

enter image description here

The result is not what I expected:

app.js, benchmark.js, board.js still contains jquery code (as you can see from the huge file size)

Webpack output

Is there anything wrong with my webpack configuration?
I just followed the example in :


plugins should be an object array outside of modules.

Also, I don't think you need the minChunks or chunks options for this use case scenario. Your vendor entry chunk should be sufficient.

entry: {
    vendor: ['jquery']
plugins: [
    new webpack.optimize.CommonsChunkPlugin({
        name: "vendor",
        minChunks: Infinity