Webpack - React Router V4 - code splitting duplicate modules in async chunks

梦想的初衷 提交于 2019-12-05 20:08:10

And I finally got the solution ;)

I let this so it might help someone.

The answer is : Not specifying chunk doesn't apparently target all the chunks but only the last one created.

So let's say with react-router V4 we've created 2 async chunks 'home-chunk' and 'welcome-chunk'. The way to get the common chunks out of it is to add in the webpack config file (in the pluggins):

new webpack.optimize.CommonsChunkPlugin( {
  name : 'common',
  chunks : ['home-chunk', 'welcome-chunk'],
  minChunks : 2,
}),

This will check if there is common modules in the async chunks and if so, put them in the common chunk.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!