How to bundle vendor scripts separately and require them as needed with Webpack?

后端 未结 4 1750
我寻月下人不归
我寻月下人不归 2020-11-28 17:51

I\'m trying to do something that I believe should be possible, but I really can\'t understand how to do it just from the webpack documentation.

I am writing a JavaSc

4条回答
  •  醉话见心
    2020-11-28 18:06

    Also not sure if I fully understand your case, but here is config snippet to create separate vendor chunks for each of your bundles:

    entry: {
      bundle1: './build/bundles/bundle1.js',
      bundle2: './build/bundles/bundle2.js',
      'vendor-bundle1': [
        'react',
        'react-router'
      ],
      'vendor-bundle2': [
        'react',
        'react-router',
        'flummox',
        'immutable'
      ]
    },
    
    plugins: [
      new webpack.optimize.CommonsChunkPlugin({
        name: 'vendor-bundle1',
        chunks: ['bundle1'],
        filename: 'vendor-bundle1.js',
        minChunks: Infinity
      }),
      new webpack.optimize.CommonsChunkPlugin({
        name: 'vendor-bundle2',
        chunks: ['bundle2'],
        filename: 'vendor-bundle2-whatever.js',
        minChunks: Infinity
      }),
    ]
    

    And link to CommonsChunkPlugin docs: http://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin

提交回复
热议问题