How to reuse webpack vendor bundle

放肆的年华 提交于 2019-12-08 18:30:43

问题


I assume that I can achieve what I am trying to do with webpack but still could not figure it out. Here is the use case.

I have couple of Angular Apps (will get loaded within same browser window) which will be reusing exactly the same vendor bundle. At the moment webpack produces two files, app.[app_module_name].js and vendor.js in each app. So theoretically I should be able to only include one vendor.js file in the html page and then load several app modules. However this does does not work since webpack internal references for lib's in vendor are different from each other.

Following is my configuration at the moment. Would be great if anyone can help me out.

entry: {
      bootstrap: './src/app/init/bootstrap.js',
      tradingApp: './src/app/app.js'
    },
    output: {
      filename: '[name].bundle.js',
      publicPath: '/',
      path: path.join(projectRoot, 'dist')
    },
plugins:[
      new webpack.optimize.CommonsChunkPlugin({
        name: 'vendor',
        minChunks: function (module) {
          return module.resource && module.resource.indexOf(path.join(projectRoot, 'src')) === -1
        }
      }),
]

来源:https://stackoverflow.com/questions/36097701/how-to-reuse-webpack-vendor-bundle

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