Webpack: CommonsChunkPlugin not work with require in .vue files

Created on 22 Feb 2017  路  5Comments  路  Source: vuejs-templates/webpack

I import moment module in 3 .vue files, but moment didn't be generated in vendor.js

https://github.com/hanai/test

jj

Most helpful comment

That is working as expected. Since all 3 of your route components require moment.js, and its up to the visitor to decide which route to go to first, webpack has to put it into each of the async bundles.

if you want to extract dependencies that are shared amongst your extractred asynv bundles, you have to create another instance of the commonChunks Plugin:

I think it should look like this:

plugins: [
 // other plugins...,
  new webpack.optimize.CommonsChunkPlugin({
    name: 'commonsasync.js',
    async; 'commonsasync',
    min: 2,
  })
]

Coincidentally, I learned about this just yesterday through this article:

https://medium.com/@adamrackis/vendor-and-code-splitting-in-webpack-2-6376358f1923#.jyz1nf7v2

...and haven't tested it. Try it out and see if that works as intended.

All 5 comments

Hello @hanai,,

thank you for your filing this issue.

Please follow the guidelines on how to report an issue. In particular, provide an example on www.jsfiddle.net (or a similar service) that reproduces the problem. If necessary, create a repository for us to clone with a minimal reproduction. repositories of actual projects will generally not be accepted.

Thank you.

repro add

thanks

That is working as expected. Since all 3 of your route components require moment.js, and its up to the visitor to decide which route to go to first, webpack has to put it into each of the async bundles.

if you want to extract dependencies that are shared amongst your extractred asynv bundles, you have to create another instance of the commonChunks Plugin:

I think it should look like this:

plugins: [
 // other plugins...,
  new webpack.optimize.CommonsChunkPlugin({
    name: 'commonsasync.js',
    async; 'commonsasync',
    min: 2,
  })
]

Coincidentally, I learned about this just yesterday through this article:

https://medium.com/@adamrackis/vendor-and-code-splitting-in-webpack-2-6376358f1923#.jyz1nf7v2

...and haven't tested it. Try it out and see if that works as intended.

@hanai If that solves your problem, please consider closing this issue.

Was this page helpful?
0 / 5 - 0 ratings