GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - unplugin/unplugin-swc: SWC plugin for Vite and Rollup

BranchesTags
Open more actions menu

Latest commit

 

History

397 Commits
397 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.vscode
.vscode
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.nvmrc
.nvmrc
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
eslint.config.js
eslint.config.js
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
pnpm-workspace.yaml
pnpm-workspace.yaml
 
 
tsconfig.json
tsconfig.json
 
 
tsup.config.ts
tsup.config.ts
 
 

Repository files navigation

unplugin-swc

npm version

SWC plugin for Vite, Rollup, and Webpack.

Requirements

  • Node.js ^20.19.0 or >=22.12.0

Install

npm i unplugin-swc @swc/core -D

Usage

Vite, Rollup, or Webpack:

import swc from 'unplugin-swc'

export default {
  plugins: [
    // Vite plugin
    swc.vite(),
    // Rollup plugin
    swc.rollup(),
    // Webpack plugin
    swc.webpack(),
  ],
}

tsconfig.json

Following SWC options are inferred from tsconfig.json:

  • jsc.parser.syntax: based on file extension
  • jsc.parser.jsx, parser.tsx: compilerOptions.jsx
  • jsc.parser.decorators: compilerOptions.experimentalDecorators
  • jsc.transform.react.pragma: compilerOptions.jsxFactory
  • jsc.transform.react.pragmaFrag: compilerOptions.jsxFragmentFactory
  • jsc.transform.react.importSource: compilerOptions.jsxImportSource
  • jsc.transform.react.runtime: automatic for compilerOptions.jsx: "react-jsx" or "react-jsxdev"; otherwise classic
  • jsc.transform.react.development: enabled for compilerOptions.jsx: "react-jsxdev"
  • jsc.transform.legacyDecorator: compilerOptions.experimentalDecorators
  • jsc.transform.decoratorMetadata: compilerOptions.emitDecoratorMetadata
  • jsc.keepClassNames: when decorator is enabled, because original class name is required by libs like type-graphql to generate correct graphql type

If you wish to disable this behavior and use .swcrc to control above jsc options, you can use tsconfigFile option:

// Or swc.rollup
swc.vite({
  tsconfigFile: false,
})

// It's also possible to use a custom tsconfig file instead of tsconfig.json
swc.vite({
  tsconfigFile: './tsconfig.build.json',
})

Minification

Use the minify: true option. It only works for Rollup. Vite uses esbuild to minify code, and Webpack minification is not supported.

To have advanced control over the minification process, use jsc.minify option in .swcrc.

Vite

esbuild will be automatically disabled if you use this plugin.

Options

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:

options.tsconfigFile

  • Type: boolean, string
  • Default: tsconfig.json

Disable the use of tsconfig file or specify a custom one.

options.include

  • Type: RegExp
  • Default: /\.[jt]sx?$/

Files to include in the transpilation process.

options.exclude

  • Type: RegExp
  • Default: /node_modules/

Files to exclude in the transpilation process.

options.jsc

  • Type: object

Custom jsc options to merge with the default one.

License

MIT © EGOIST

About

SWC plugin for Vite and Rollup

Resources

Readme
MIT license

Code of conduct

Code of conduct

Contributing

Contributing
Activity
Custom properties

Stars

274 stars

Watchers

1 watching

Forks

19 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

Generated from egoist/ts-lib-starter
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.