webpack-5 - 如何将简洁的 webpack 插件迁移到 webpack v5

标签 webpack-5

If you are using webpack v5 or above you do not need to install this plugin. Webpack v5 comes with the latest terser-webpack-plugin out of the box.

我将使用 webpack v5,所以根据文档,我删除了 terser:npm uninstall terser-webpack-plugin。但我不确定如何迁移为 webpack v4 + TerserPlugin 设置的以下设置:

optimization: {
    minimizer: [
      new TerserPlugin({
        sourceMap: true,
        terserOptions: {
          output: {
            comments: /^!/,
          },
        },
        extractComments: false,
      }),
    ],
  },

我无法在线找到该文档。请问有人可以帮忙吗?

最佳答案

我正在使用以下 TerserPlugin 配置,它适用于 webpack v5!

  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        test: /\.js(\?.*)?$/i, // you should add this property
        extractComments: false,
        terserOptions: {
          compress: {
            drop_console: true,
            drop_debugger: true,
            pure_funcs: ['console.log', 'console.info'], // Delete console
          },
        },
      }),
    ],
  },

关于webpack-5 - 如何将简洁的 webpack 插件迁移到 webpack v5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66801321/

相关文章:

webpack - 路径连接在 webpack 5 中不起作用,但在 webpack 4 中起作用

javascript - 无法从 'C:\Users\syrine\management\node_modules\stylis-plugin-rtl\src\stylis-rtl.ts' 解析源映射

Webpack 5 HMR 问题 - 无法读取未定义的属性 'updatedChunkIds'

javascript - Webpack 5 : file-loader generates a copy of fonts with hash-name

reactjs - 为什么上下文提供者状态不在微前端之间共享?

javascript - 错误 : while using devtool ="source-map" option in webpack config version 5

javascript - 使用最新的 terser-webpack-plugin 和 Webpack5

webpack - 如何在 webpack 配置中保存 contenthash

javascript - WP5 模块联盟 : Singleton instantiated multiple times

reactjs - 错误 : Prevent writing to file that only differs in casing or query string from already written file. reactjs laravel