unplugin-swc

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

unplugin-swc v1.5.9 is a build tool plugin that integrates SWC (Speedy Web Compiler) into Vite and Rollup pipelines. It automatically infers SWC options from tsconfig.json, simplifying migration from Babel/tsc. Released under MIT, actively maintained with frequent updates (monthly releases). Key differentiator: it replaces esbuild in Vite automatically, supports minification in Rollup, and recognizes .mts files (v1.5+). Peer dependency on @swc/core ^1.2.108.

error Cannot find module 'unplugin-swc'
cause Missing peer dependency @swc/core or wrong package manager cache.
fix
Run: npm install unplugin-swc @swc/core -D
error TypeError: swc.vite is not a function
cause Using CommonJS require() instead of ESM import.
fix
Use: import swc from 'unplugin-swc'
error Error: [unplugin-swc] 'minify' only works with rollup
cause Using minify: true for Vite plugin, which is unsupported.
fix
Remove minify option from Vite plugin, or use Rollup plugin if minification needed.
error Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
cause unplugin-swc is not correctly included in Vite/Rollup configuration; often due to missing plugin registration.
fix
Ensure plugin is added to the plugins array: swc.vite() for Vite or swc.rollup() for Rollup.
breaking Package is ESM-only since v1.5.1; requires 'type': 'module' in package.json or .mjs extension.
fix Use import syntax and set type: module in package.json.
deprecated Using require('unplugin-swc') is deprecated; ESM-only from v1.5.1 onward.
fix Switch to import statements.
gotcha The minify option only works with Rollup, not Vite (Vite uses esbuild for minification and cannot be changed).
fix Only enable minify for Rollup builds; for Vite, use esbuild minify configuration directly.
gotcha Setting jsc options in plugin options may conflict with .swcrc or tsconfig.json inference. It's recommended to configure jsc in .swcrc instead.
fix Use .swcrc for jsc options, or set tsconfigFile: false to disable tsconfig inference.
breaking In version 1.5.0, .mts files are now recognized; if you relied on previous behavior of ignoring .mts, update your include/exclude regex.
fix Adjust include/exclude patterns if needed; .mts is now included by default.
gotcha When using experimentalDecorators, jsc.keepClassNames is automatically enabled; this may affect class naming in production builds.
fix If you don't need keepClassNames, set tsconfigFile: false and configure SWC manually.
npm install unplugin-swc
yarn add unplugin-swc
pnpm add unplugin-swc

Minimal Vite configuration using unplugin-swc with tsconfig inference and optional minification.

import swc from 'unplugin-swc'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    swc.vite({
      tsconfigFile: './tsconfig.json',
      include: /\.[jt]sx?$/,
      exclude: /node_modules/,
      minify: process.env.NODE_ENV === 'production'
    })
  ]
})