安装模块大小自动分割第三方库

121 阅读1分钟

安装模块大小自动分割第三方库

使用 splitChunks 安装正则进行分割


  configureWebpack: (config) => {
    config.optimization.splitChunks = {
      maxInitialRequests: Infinity,
      minSize: 300 * 1024,
      chunks: 'all',
      cacheGroups: {
        elmVendor: {
          test: /[\\/]node_modules[\\/]/,
          name(module) {
            // get the name.
            // node_modules/packageName/sub/path
            // or node_modules/packageName
            const packageName = module.context.match(
              /[\\/]node_modules[\\/](.*?)([\\/]|$)/
            )[1]
            return `npm.${packageName.replace('@', '')}`
          }
        }
      }
    }
  }

Snipaste_2023-07-21_10-40-14.jpg