hyperse-io/unplugin-swc(新しいタブで開きます)
主要言語: TypeScript
SWC plugin for Vite and Rollup supporting ESM modules
- star 数
- 2
- watcher 数
- 1
- fork 数
- 1
- issue 数
- 0
- 最終更新
- 2026/10/15
主要言語: TypeScript
SWC plugin for Vite and Rollup supporting ESM modules
A high-performance SWC plugin for Vite and Rollup that provides fast TypeScript/JavaScript compilation and transformation.
Vite or Rollup:
import { unpluginSwc } from '@hyperse/unplugin-swc'; export default { plugins: [ unpluginSwc.vite({ jsc: { target: 'es2022', // Does not accept `esnext` } }, }), ], };
Following SWC options are inferred from tsconfig.json:
jsc.parser.syntax: based on file extensionjsc.parser.jsx, parser.tsx: compilerOptions.jsxjsc.parser.decorators: compilerOptions.experimentalDecoratorsjsc.transform.react.pragma: compilerOptions.jsxFactoryjsc.transform.react.pragmaFrag: compilerOptions.jsxFragmentFactoryjsc.transform.react.importSource: compilerOptions.jsxImportSourcejsc.transform.legacyDecorator: compilerOptions.experimentalDecoratorsjsc.transform.decoratorMetadata: compilerOptions.emitDecoratorMetadatajsc.keepClassNames: when decorator is enabled, because original class name is required by libs like type-graphql to generate correct graphql typeIf you wish to disable this behavior and use .swcrc to control above jsc options, you can use tsconfigFile option:
// Or swc.rollup unpluginSwc.vite({ tsconfigFile: false, }); // It's also possible to use a custom tsconfig file instead of tsconfig.json unpluginSwc.vite({ tsconfigFile: './tsconfig.build.json', });
If you are using TypeORM with Vitest and need support for decorators, you can switch from esbuild to SWC by configuring Vitest as follows:
import tsconfigPaths from 'vite-tsconfig-paths'; import { configDefaults, defineConfig } from 'vitest/config'; import { unpluginSwc } from '@hyperse/unplugin-swc'; export default defineConfig({ // `esbuild` will be automatically disabled if you use this plugin. plugins: [tsconfigPaths(), unpluginSwc.vite({})], test: { globals: true, exclude: [...configDefaults.exclude], include: ['**/?(*.){test,spec}.?(c|m)[jt]s?(x)'], }, });
Use the minify: true option, it only works for Rollup as Vite uses esbuild to minify the code and cannot be changed.
To have advanced control over the minification process, use jsc.minify option in .swcrc.
esbuild will be automatically disabled if you use this plugin.
This plugin accepts all @swc/core options, except for jsc which should be configured in .swcrc instead, and some extra options that are specific to this plugin:
boolean, stringtsconfig.jsonDisable the use of tsconfig file or specify a custom one.
RegExp/\.[jt]sx?$/Files to include in the transpilation process.
RegExp/node_modules/Files to exclude in the transpilation process.
objectCustom jsc options to merge with the default one.
For automatic resolution of TypeScript path aliases from tsconfig.json in Rollup, you can check out: