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.
Common errors
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
Warnings
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'].
Install
npm install rollup-plugin-swc3 yarn add rollup-plugin-swc3 pnpm add rollup-plugin-swc3 Imports
- swcPlugin wrong
import swcPlugin from 'rollup-plugin-swc3'correctimport { swcPlugin } from 'rollup-plugin-swc3' - swcMinify
import { swcMinify } from 'rollup-plugin-swc3' - viteMinify wrong
import { viteMinify } from 'rollup-plugin-swc3'correctimport { viteMinify } from 'rollup-plugin-swc3'
Quickstart
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
}
}
})
]
};