Terser Webpack Plugin Legacy

raw JSON →
1.2.5 verified Sat Apr 25 auth: no javascript maintenance

Terser plugin for webpack 3.x to minify JavaScript using terser. Legacy version (v1.2.5) for webpack 3, maintained separately from the main terser-webpack-plugin which targets webpack 4+. Uses terser for modern ES6+ syntax support compared to uglify-js. Limited to Node >= 6.9.0 and webpack ^3.0.0. Not recommended for new projects; use terser-webpack-plugin (non-legacy) for webpack 4+.

error Module not found: Error: Can't resolve 'terser-webpack-plugin'
cause Incorrect package name; installed the wrong package or not installed.
fix
Run: npm install terser-webpack-plugin-legacy --save-dev
error TypeError: Cannot read property 'tapAsync' of undefined
cause Plugin incompatible with webpack 4+ because it uses webpack 3 hooks.
fix
Use terser-webpack-plugin (non-legacy) for webpack 4+.
error Error: webpack.optimize.UglifyJsPlugin is not a constructor
cause Misunderstanding: using UglifyJsPlugin when terser plugin should be used.
fix
Use TerserPlugin from 'terser-webpack-plugin-legacy' instead.
gotcha Package name is `terser-webpack-plugin-legacy`, not `terser-webpack-plugin`. Using the wrong package will install the modern version for webpack 4+.
fix Install `terser-webpack-plugin-legacy` and require it as shown.
breaking Only compatible with webpack ^3.0.0. Will not work with webpack 4+.
fix Upgrade to `terser-webpack-plugin` (non-legacy) for webpack 4+.
deprecated Legacy plugin; not actively developed. Consider migrating to the non-legacy version.
fix Use `terser-webpack-plugin` (v4+) for new projects.
gotcha Default caching to `node_modules/.cache/terser-webpack-plugin` may cause issues in CI.
fix Set `cache: false` or a custom path to avoid permission errors.
gotcha The `sourceMap` option must be enabled in webpack config for source maps to work.
fix Add `devtool: 'source-map'` to webpack config.
npm install terser-webpack-plugin-legacy
yarn add terser-webpack-plugin-legacy
pnpm add terser-webpack-plugin-legacy

Sets up terser-webpack-plugin-legacy in webpack 3 config with cache enabled and console removal.

const TerserPlugin = require('terser-webpack-plugin-legacy');

module.exports = {
  context: __dirname,
  entry: './src/index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'bundle.js'
  },
  optimization: {
    minimizer: [
      new TerserPlugin({
        test: /\.js(\?.*)?$/i,
        cache: true,
        terserOptions: {
          compress: {
            drop_console: true
          }
        }
      })
    ]
  }
};