# vite-plugin-swc-transform

> Vite plugin for transforming source files with SWC.

Latest version **1.1.1** (published 2025-09-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-swc-transform
pnpm add vite-plugin-swc-transform
yarn add vite-plugin-swc-transform
bun add vite-plugin-swc-transform
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2025-09-01 |
| First published | 2023-10-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | ^18.0.0 \|\| ^20.0.0 \|\| >=22.0.0 |
| Dependencies | 2 |
| Unpacked size | 20.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Timothée “Tim” Pillard |
| Maintainers | ziir |
| Keywords | vite, plugin, vite-plugin, swc, transform, typescript, decorator, metadata, reflect, nest, typeorm, dependency injection |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-swc-transform
- Repository: https://github.com/ziir/vite-plugin-swc-transform
- Homepage: https://github.com/ziir/vite-plugin-swc-transform/#readme
- Issues: https://github.com/ziir/vite-plugin-swc-transform/issues
- npm.io page: https://npm.io/package/vite-plugin-swc-transform

## Dependencies (2)

- [@swc/core](https://npm.io/package/@swc/core.md) ^1.10.3
- [@rollup/pluginutils](https://npm.io/package/@rollup/pluginutils.md) ^5.1.4

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2025-09-01
- 1.2.0-beta.1 (next) — 2025-04-18
- 1.1.0 — 2025-01-03
- 1.1.0-alpha.2 — 2024-12-29
- 1.1.0-alpha.1 — 2024-12-28
- 1.0.1 — 2024-06-23
- 1.0.0 — 2024-06-23
- 1.0.0-alpha.1 — 2024-06-23
- 0.5.0-beta.1 — 2024-06-17
- 0.4.0 — 2024-05-27
- 0.4.0-beta.3 — 2024-05-27
- 0.4.0-beta.2 — 2024-05-27
- 0.4.0-beta.1 — 2024-05-12
- 0.4.0-beta — 2024-05-12
- 0.4.0-alpha — 2024-05-05
- … 5 more at https://npm.io/package/vite-plugin-swc-transform/versions

## README

# vite-plugin-swc-transform [![npm](https://img.shields.io/npm/v/vite-plugin-swc-transform)](https://www.npmjs.com/package/vite-plugin-swc-transform)

Transform your TypeScript / JavaScript source files with [SWC](https://swc.rs) within your [Vite](vitejs.dev/) **build** process.

- Sane defaults for [TypeScript's legacy / experimental decorators & metadata](https://www.typescriptlang.org/docs/handbook/decorators.html).
- Full control over the rest of [SWC's configuration](https://swc.rs/docs/configuration).

Read the blog post relating the story which led to the creation of this plugin: [TypeScript Legacy Experimental Decorators with Type Metadata in 2023](https://timtech.blog/posts/transform-typescript-legacy-decorators-vite-swc-plugin/).

## Installation

```sh
npm i --save-dev vite-plugin-swc-transform
```

## Usage

_Note:_ This package is **ESM-only**.

### Default [SWC](https://swc.rs/docs/configuration) transform options

```js
import { defineConfig } from "vite";
import swc from "vite-plugin-swc-transform";

export default defineConfig({
  plugins: [swc()],
});
```

The plugin will default to the following options:

```js
{
  include: /\.tsx?$/,
  exclude: /node_modules/,

  swcOptions: {
    {
      swcrc: false,
      configFile: false,
      inputSourceMap: false,
      sourceMaps: true
    }
  },

  suppressLegacyDecoratorNoExplicitUDFCFWarning: false
}
```

### Transform TypeScript Legacy / Experimental Decorators with Metadata

Example use case: build a package leveraging [Nest](https://docs.nestjs.com/providers) style **dependency injection** with [Reflect.metadata](https://github.com/rbuckton/reflect-metadata).

```js
import { defineConfig } from "vite";
import swc from "vite-plugin-swc-transform";

export default defineConfig({
  plugins: [
    swc({
      swcOptions: {
        jsc: {
          target: "es2022",
          transform: {
            legacyDecorator: true,
            decoratorMetadata: true,
            useDefineForClassFields: false,
          },
          // externalHelpers: true,
        },
      },
    }),
  ],
});
```

**Notes:**

- should be used alongside `"compilerOptions.experimentalDecorators": true` & `"compilerOptions.emitDecoratorMetadata": true` in your `tsconfig.json`.
- [`swcOptions.jsc.externalHelpers: true`](https://swc.rs/docs/configuration/compilation#jscexternalhelpers) is recommended when transforming TypeScript Legacy / Experimental Decorators with Metadata to avoid helpers duplication & limit bundle size impact.
  - adding the `@swc/helpers` dependency is then necessary.

The above (without external helpers) will yield the following SWC transform options:

```js
{
  swcrc: false,
  configFile: false,
  inputSourceMap: false,
  sourceMaps: true,
  jsc: {
    target: 'es2022',
    transform: {
      legacyDecorator: true,
      decoratorMetadata: true,
      useDefineForClassFields: false
    },
    keepClassNames: true,
    parser: {
      decorators: true,
      decoratorsBeforeExport: true,
      syntax: 'typescript'
    }
  }
}
```

### Notes

- This plugin does not read, validate or infer from the project's `tsconfig.json` configuration.
- This plugin is intended to be used with an inlined `swcOptions` SWC configuration object.

### 'useDefineForClassFields' warning

```
[vite-plugin-swc-transform] SWC option 'jsc.transform.legacyDecorator' enabled without an explicit 'jsc.transform.useDefineForClassFields' value.
To remove this warning, either:
 - unset or disable SWC option 'jsc.transform.legacyDecorator' if not needed
 - set an explicit value for SWC option 'jsc.transform.useDefineForClassFields: boolean'
 - pass vite-plugin-swc-transform option 'suppressLegacyDecoratorNoExplicitUDFCFWarning: true'
```

[Learn more](https://twitter.com/tpillard/status/1714545623813218388);

Please open an issue if you think this is incorrect or should be improved.

---
_Source: https://npm.io/package/vite-plugin-swc-transform · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
