Webpack拆分块插件生产版本

时间:2019-10-12 11:52:05

标签: webpack

** Webpack拆分块插件-下面的代码-在生产模式下不会生成antd.bundle.js。     在开发模式下,它可以正常工作,并生成3个捆绑文件-react.bundle.js,antd.bundle.js和common.bundle.js。 **

optimization: {
  splitChunks: {
    cacheGroups: {
      react: {
        test: /[\\/]node_modules[\\/]((react).*[\\/])/,
        name: 'common/react.bundle',
        chunks: 'all',
      },
      antd: {
        test: /[\\/]node_modules[\\/]((antd).*[\\/])/,
        name: 'common/antd.bundle',
        chunks: 'all',
      },
      common: {
        test(mod/* , chunk */) {

          if (mod.context) {
            // Only node_modules are needed
            if (!mod.context.includes('node_modules')) {
              return false;
            }
            // But not node modules that contain these key words in the path
            if (['react', 'antd'].some((str) => mod.context.includes(str))) {
              return false;
            }
          }

          return true;
        },
        name: 'common/common.bundle',
        chunks: 'all',
        reuseExistingChunk: true,
      },
    },
  },
},

0 个答案:

没有答案
相关问题