rollup-plugin-swc-minify

raw JSON →
1.3.0 verified Mon Apr 27 auth: no javascript

Rollup plugin to minify generated bundles using swc. Version 1.3.0 supports Rollup ^2, ^3, or ^4 and requires Node.js >= 14.18. It focuses solely on minification, making it simpler than rollup-plugin-swc which does transpilation. It is benchmarked to be faster than @rollup/plugin-terser. Provides options for format, sourcemap, and sourcemapExcludeSources. Licensed under MIT.

error Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'rollup-plugin-swc-minify'
cause Package not installed or mismatched rollup peer dependency version.
fix
Run npm install -D rollup-plugin-swc-minify and ensure rollup version is ^2 || ^3 || ^4.
error Error: 'minify' is not exported from 'rollup-plugin-swc-minify'
cause Using default import or wrong import syntax.
fix
Use the named import: import { minify } from 'rollup-plugin-swc-minify'.
error Error: The specified module could not be found. (ERR_REQUIRE_ESM)
cause Attempting to require() the ESM-only package.
fix
Use import instead of require(), or set type: 'module' in package.json.
error Error: Rollup plugin 'minify' is not a function
cause Using the plugin as a class/constructor instead of calling the function.
fix
Use minify() (call the function) instead of new minify() or just minify.
breaking Package is ESM-only; require() will throw ERR_REQUIRE_ESM.
fix Use import statements or dynamic import() instead of require().
gotcha The plugin does not transpile code; it only minifies. If you need JSX/TypeScript support, use rollup-plugin-swc or another transpiler first.
fix Use rollup-plugin-swc for transpilation before minification.
gotcha The 'format' option only affects minification output, not Rollup's output format. Ensure Rollup output format matches.
fix Set rollup output.format appropriately (e.g., 'es') and optionally pass format to minify() for accurate minification.
deprecated The 'sourcemapExcludeSources' option may be removed in future versions; use source maps carefully.
fix Set sourcemap: true and control source map content via Rollup options if possible.
npm install rollup-plugin-swc-minify
yarn add rollup-plugin-swc-minify
pnpm add rollup-plugin-swc-minify

Minifies the bundle with swc, supporting ES module format and sourcemaps.

import { minify } from 'rollup-plugin-swc-minify';

export default {
  input: 'src/index.js',
  output: { file: 'dist/main.js', format: 'iife', sourcemap: true },
  plugins: [
    minify({ format: 'es', sourcemap: true })
  ]
};