rollup-plugin-swc3

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

Rollup plugin that uses SWC (a Rust-based transpiler) for fast ESNext/TypeScript compilation. Version 0.12.1 is current (released Oct 2023), targeting Node >=16 with peer deps on @swc/core >=1.2.165 and Rollup 2/3/4. Differentiators vs other SWC Rollup plugins: built-in minification (swcMinify), tsconfig/jsconfig reading, viteMinify helper, ESM-only exports, and TypeScript declarations. Actively maintained with frequent releases. Replaces rollup-plugin-typescript2, @rollup/plugin-typescript, and @rollup/plugin-babel.

error TypeError: (0 , rollup_plugin_swc3.swcPlugin) is not a function
cause Default import used instead of named import.
fix
Change to import { swcPlugin } from 'rollup-plugin-swc3'
error Error: The 'tsconfig' option expects a string, got undefined
cause Missing or misspelled tsconfig option.
fix
Provide a valid tsconfig path: swcPlugin({ tsconfig: 'tsconfig.json' })
error Error: Cannot find module '@swc/core'
cause @swc/core not installed or is a devDependency not available at runtime.
fix
Run npm install @swc/core --save
error Error: rollup-plugin-swc3 requires Rollup >=2.0.0
cause Incompatible Rollup version (e.g., 1.x).
fix
Upgrade Rollup: npm install rollup@latest
breaking Minimum Node version bumped from 12 to 16 in 0.12.0
fix Upgrade Node.js to >=16
breaking Decorator detection changed in 0.12.0: TypeScript 5 enables 2022-03 decorators automatically; older TS uses experimentalDecorators from tsconfig.
fix Review decorator settings; set jsc.parser.decorators explicitly if needed.
deprecated preserveUseDirective export deprecated since 0.9.1; replaced by standalone rollup-preserve-directives plugin.
fix Use import { preserveDirectives } from 'rollup-preserve-directives' instead.
gotcha Module resolution only applies to files within include/exclude patterns (since 0.11.0).
fix Ensure all source files are covered by include option, or set include to ['**/*.ts'].
npm install rollup-plugin-swc3
yarn add rollup-plugin-swc3
pnpm add rollup-plugin-swc3

Basic Rollup config using swcPlugin to transpile TypeScript to ES2020 and minify output.

import { swcPlugin } from 'rollup-plugin-swc3';

export default {
  input: 'src/index.ts',
  output: { dir: 'dist', format: 'esm' },
  plugins: [
    swcPlugin({
      tsconfig: 'tsconfig.json',
      minify: true,
      jsc: {
        target: 'es2020',
        parser: {
          syntax: 'typescript',
          decorators: true
        }
      }
    })
  ]
};