swc-minify-webpack-plugin

raw JSON →
2.1.3 verified Sat Apr 25 auth: no javascript

A webpack plugin that uses swc.minify() to minify JavaScript bundles, offering faster performance than terser-webpack-plugin's swc mode. Current stable version is 2.1.3, released under Apache 2.0 license. It provides simpler options, enables mangle by default for better compression, and is a fork of swc-webpack-plugin with improved performance by using swc.minify() instead of swc.transform(). Requires webpack 5+ and @swc/core 1+ as peer dependencies. Ships TypeScript type definitions.

error Error: Cannot find module 'swc-minify-webpack-plugin'
cause Package not installed or incorrect import path.
fix
Run npm install -D swc-minify-webpack-plugin and ensure import uses require or import correctly.
error TypeError: SwcMinifyWebpackPlugin is not a constructor
cause Using default import instead of named import in v2.
fix
Use named import: import { SwcMinifyWebpackPlugin } from 'swc-minify-webpack-plugin'
error ValidationError: Invalid options object. Minimizer Plugin has been initialized using an options object that does not match the API schema.
cause Incorrect options passed to SwcMinifyWebpackPlugin constructor.
fix
Check options: only compress, mangle, and format are supported. Pass them as an object: new SwcMinifyWebpackPlugin({ compress: false })
breaking v2.0.0: Changed default export to named export. Import must use destructuring.
fix Change `import SwcMinifyWebpackPlugin from 'swc-minify-webpack-plugin'` to `import { SwcMinifyWebpackPlugin } from 'swc-minify-webpack-plugin'`
deprecated v1.x: The default export pattern is deprecated and will not work with v2.
fix Upgrade to v2 and use named export.
gotcha Configuration options `compress`, `mangle`, and `format` are passed directly to swc.minify(). Incorrect options may silently fail or produce unexpected output.
fix Refer to swc documentation for valid options: https://swc.rs/docs/configuration/minification
npm install swc-minify-webpack-plugin
yarn add swc-minify-webpack-plugin
pnpm add swc-minify-webpack-plugin

Basic usage of swc-minify-webpack-plugin as the sole minimizer in webpack's optimization configuration.

// webpack.config.js
const { SwcMinifyWebpackPlugin } = require('swc-minify-webpack-plugin');

module.exports = {
  optimization: {
    minimize: true,
    minimizer: [new SwcMinifyWebpackPlugin()],
  },
};