Vite plugin to transform TypeScript/JavaScript source files with SWC during the build process. Current stable version is 1.1.1, released with support for Vite 5, 6, and 7. It provides sane defaults for legacy/experimental decorators and metadata, and gives full control over SWC configuration. Unlike esbuild (Vite's default), it supports TypeScript legacy decorators with metadata. ESM-only, ships TypeScript declarations, and requires Node >=18.
npm install vite-plugin-swc-transformVerified import paths — ran on the pinned version, not inferred.
Enables legacy decorators with metadata transformation using SWC in Vite build.
Migrate to TC39 stage 3 decorators when possible; use SWC's new decorator options.
Set all needed SWC options in swcOptions; do not rely on tsconfig.json.
Use import syntax or dynamic import(). Ensure project is configured for ESM.
Set 'useDefineForClassFields: false' (or true) explicitly, or set suppressLegacyDecoratorNoExplicitUDFCFWarning: true.
Add '@swc/helpers' to your project's dependencies.
For dev transformations, use SWC via Vite's esbuild or another plugin like vite-plugin-esbuild.
Use import statement or dynamic import(). Ensure project type is 'module' in package.json.
Use import swc from 'vite-plugin-swc-transform' (no curly braces).
Set 'useDefineForClassFields' to false (or true) in swcOptions.jsc.transform.