Skip to content
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

commonsChunkPlugins async options Invalid #5101

Closed
lijinke666 opened this issue Jun 20, 2017 · 12 comments
Closed

commonsChunkPlugins async options Invalid #5101

lijinke666 opened this issue Jun 20, 2017 · 12 comments
Labels

Comments

@lijinke666
Copy link

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

What is the current behavior?

  • I am using webpack2.4.0, in my webpack.config.js use plugin webpack.optimize.COmmonsChunkPlugin options async and minChunks
  • like
new webpack.optimize.CommonsChunkPlugin({
  async:"used-twice",
  minChunks:(module,count)=> ( count >=2 )
})
  • That's fine, in my project I have a generated file used-twice.js
    If the current behavior is a bug, please provide the steps to reproduce.
  • but I today upgrade webpack@.2.4 => webpack@3.0.0 found webpack.optimize.COmmonsChunkPlugin options async invalid
  • can't build file used-twice.js
  • after I use yarn add other webpack versions like v.2.5 v.2.6.0 v.3.0.0 All invalid :(
  • but webpack@2.4.0 succeed
  • I don't know how to solve it ! Please help me, Thanks.
  • English is so tired with Google

What is the expected behavior?

  • build a common chunk file used-twice.js

If this is a feature request, what is motivation or use case for changing the behavior?

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

  • window
  • node 8.1.0
  • webpack 2.6.0
@aseem2625
Copy link

aseem2625 commented Jun 20, 2017

I've been using "webpack": "^2.5.1" until now and this below used to work.

  new webpack.optimize.CommonsChunkPlugin({
    names: ['vendor'],
    minChunks: function(module) {
      return module.context && module.context.indexOf('node_modules') !== -1;
    },
  }),

  new webpack.optimize.CommonsChunkPlugin({
    name: 'manifest', //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
  }),

Upgrading to webpack 3.0.0 started throwing error Uncaught TypeError: Cannot read property 'call' of undefined in the browser in manifest.js.

Changing it to below worked for me


  new webpack.optimize.CommonsChunkPlugin({
    names: ['vendor', 'manifest'],
  }),

@lijinke666
I'm not sure how will it work in your way. And also, I would be waiting for the bug to get fixed as above 2 code aren't exactly same.

@aseem2625
Copy link

aseem2625 commented Jun 20, 2017

@lijinke666
Please update your post telling that webpack you used v3.0.0 to produce the bug

You originally have written:

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

window
node 8.1.0
webpack 2.6.0

@lijinke666
Copy link
Author

@aseem2625 Thanks

  • I upgrade webpackv3.0.0 is no problem,
  • Only now used -twice files cannot be extracted separately, My build files increased by 600 KB
  • like i have two routes , Reference the import moment I used to use webpackv2.4.0 ,After packaging
    moment.js in my used-twice.js files , Extraction of success, It's nice. This effect cannot be achieved after the update
  • The commonsChunkPlugin plugin I used it three times In my webpack.config.js file
       new webpack.optimize.CommonsChunkPlugin({
                async:"common-in-lazy",
                minChunks:({ resource } = {} )=>(
                    resource &&
                    resource.includes('node_modules') &&
                    /axios/.test(resource)
                )
            }),
            new webpack.optimize.CommonsChunkPlugin({
                async: 'used-twice',
                minChunks: (module, count) => (
                    count >= 2
                ),
            }),
            new webpack.optimize.CommonsChunkPlugin({
                name:'vender',
                filename:"js/common.[chunkhash:8].js",
                minChunks:({ resource})=>(
                    resource &&
                    resource.indexOf('node_modules') >=0 &&
                    resource.match(/\.js$/)
                )
            }),
  • After the upgrade async options is invalid I'm very upset , I'm still going to go back to webpack2.4
  • I looked at the official documents and found no solution :(

@aseem2625
Copy link

aseem2625 commented Jun 21, 2017

@lijinke666
Same here, spent a lot of time yesterday and then some guy pointed out to me a solution.
Check this.

jantimon/html-webpack-plugin#705 (comment)

I'm temporarily using this as of now. It's a bug in html webpack plugin due to un-updated dependency in this node module. All worked fine, so I kept mine CommonChunksPlugin setup which I posted initially above.. Additionally I added concatenation plugin as well. Overall, I noticed decreased in vendor.js and main.js. Build time increased slightly.

"html-webpack-plugin": "https://github.com/Re-Rabbit/html-webpack-plugin.git" 

Concluding the steps, I followed:

  1. yarn upgrade webpack
  2. Changed html webpack plugin to above package
  3. Added concatenation plugin.

Everything then worked fine.

@lijinke666
Copy link
Author

@aseem2625
Thanks I'll try it

@hacke2
Copy link

hacke2 commented Jun 27, 2017

@lijinke666 see #4850

@lijinke666
Copy link
Author

@hacke2 thank you! nice

@lijinke666
Copy link
Author

@aseem2625 I have solved it with hacke2 help ,But thank you anyway :)

@aseem2625
Copy link

Nice 👍

@tikijian
Copy link

+1
worked with webpack2.4.0
not working on 3.5

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants