swc-webpack-plugin

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

A webpack plugin that minifies bundles using swc, a fast Rust-based JS/TS minifier. Version 1.0.0 is the current stable release. It integrates as a custom minimizer in webpack's optimization pipeline, offering a synchronous mode option. Key differentiators: leverages swc's speed (often faster than Terser), supports all swc configuration options, and works with webpack 4 and 5. Ships TypeScript types.

error Module not found: Error: Can't resolve '@swc/core'
cause @swc/core not installed or not resolved.
fix
Run 'npm install --save-dev @swc/core' to install peer dependency.
error TypeError: SWCMinifyPlugin is not a constructor
cause CJS destructure not used; imported default instead of named export.
fix
Use const { SWCMinifyPlugin } = require('swc-webpack-plugin');
error Error: Cannot find module 'swc-webpack-plugin'
cause Package not installed or typo in import.
fix
Run 'npm install --save-dev swc-webpack-plugin' and check spelling.
gotcha swc-webpack-plugin does not support all swc options; some may be ignored or cause errors.
fix Check plugin documentation for supported options. Use @swc/core directly for full control.
deprecated Node.js >=10 is deprecated; consider upgrading for security and compat.
fix Upgrade Node.js to >=14 or higher.
breaking Peer dependency @swc/core ^1.2.0 required; older versions may break.
fix Ensure @swc/core is at least 1.2.0.
gotcha The plugin may not work with webpack 4 if certain features are missing.
fix Test thoroughly; consider webpack 5.
npm install swc-webpack-plugin
yarn add swc-webpack-plugin
pnpm add swc-webpack-plugin

Adds swc minification to a webpack config by replacing the default minimizer with SWCMinifyPlugin.

const { SWCMinifyPlugin } = require('swc-webpack-plugin');
const path = require('path');

module.exports = {
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  optimization: {
    minimize: true,
    minimizer: [new SWCMinifyPlugin()],
  },
};