顾名思义, 用来配置打包代码的优化项

语法:

一个对象

可用的优化项

  • 代码压缩

实例:

optimization: {
    chunkIds: "size",
    // method of generating ids for chunks
    moduleIds: "size",
    // method of generating ids for modules
    mangleExports: "size",
    // rename export names to shorter names
    minimize: true,
    // minimize the output files
    minimizer: [new CssMinimizer (), "..."],
    // minimizers to use for the output files
 
    /* Advanced optimizations (click to show) */
 
    splitChunks: {
      cacheGroups: {
        "my-name": {
          // define groups of modules with specific
          // caching behavior
          test: /\.sass$/,
          type: "css/mini-extract",
 
          /* Advanced selectors (click to show) */
 
          /* Advanced effects (click to show) */
        }
      },
 
      fallbackCacheGroup: { /* Advanced (click to show) */ }
 
      /* Advanced selectors (click to show) */
 
      /* Advanced effects (click to show) */
 
      /* Expert settings (click to show) */
    }
  },