{"id":15415017,"url":"https://github.com/sukkaw/rollup-plugin-swc","last_synced_at":"2025-05-15T14:06:26.157Z","repository":{"id":37011884,"uuid":"427855856","full_name":"SukkaW/rollup-plugin-swc","owner":"SukkaW","description":"Use SWC with Rollup to transform / minify ESNext and TypeScript code.","archived":false,"fork":false,"pushed_at":"2024-12-11T15:08:47.000Z","size":778,"stargazers_count":166,"open_issues_count":2,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-31T19:09:45.108Z","etag":null,"topics":["esnext","jsx","minifier","rollup","rollup-plugin","swc","tsx","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SukkaW.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-14T06:34:08.000Z","updated_at":"2025-03-12T14:36:17.000Z","dependencies_parsed_at":"2023-12-01T02:47:21.649Z","dependency_job_id":"43703205-3169-4031-ba72-679ee1cc8999","html_url":"https://github.com/SukkaW/rollup-plugin-swc","commit_stats":{"total_commits":164,"total_committers":11,"mean_commits":"14.909090909090908","dds":0.09146341463414631,"last_synced_commit":"28b29c7a0eba94ccc2aad43bced4ccc223ce37f6"},"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SukkaW%2Frollup-plugin-swc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SukkaW%2Frollup-plugin-swc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SukkaW%2Frollup-plugin-swc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SukkaW%2Frollup-plugin-swc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SukkaW","download_url":"https://codeload.github.com/SukkaW/rollup-plugin-swc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247721898,"owners_count":20985084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["esnext","jsx","minifier","rollup","rollup-plugin","swc","tsx","typescript"],"created_at":"2024-10-01T17:05:35.176Z","updated_at":"2025-04-07T20:09:03.224Z","avatar_url":"https://github.com/SukkaW.png","language":"TypeScript","funding_links":["https://github.com/sponsors/SukkaW/"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://pic.skk.moe/file/sukkaw/gh/rollup-plugin-swc.png\" width=\"550px\"\u003e\n\u003c/div\u003e\n\u003ch1 align=\"center\"\u003erollup-plugin-swc\u003c/h1\u003e\n\n[SWC](https://swc.rs/) is an extensible Rust-based platform for the next generation of fast developer tools. This plugin is designed to replace `rollup-plugin-typescript2`, `@rollup/plugin-typescript`, `@rollup/plugin-babel` and `rollup-plugin-terser` for you.\n\n**New:** Building library for React Server Component support is added in `0.9.0`! `'use client'` and `'use server'` directives now are handled properly, without triggering rollup warnings. [Start using `'use client'` and `'use server'` in your library by adding two lines in your `rollup.config.js`](#react-server-component-directives-use-client-and-use-server)\n\n\u003e Since `0.9.1` the support for `'use client'` and `'use server'` has been separated into a standalone rollup plugin [`rollup-preserve-directives`](https://github.com/huozhi/rollup-preserve-directives), the previous `preserveUseDirective` named export is retained for the backward compatibility.\n\n## Comparison\n\n|                                                | [sukkaw/rollup-plugin-swc](https://github.com/SukkaW/rollup-plugin-swc) | [mentaljam/rollup-plugin-swc](https://github.com/mentaljam/rollup-plugin-swc) | [nicholasxjy/rollup-plugin-swc2](https://github.com/nicholasxjy/rollup-plugin-swc2) | [@rollup/plugin-swc](https://github.com/rollup/plugins/tree/master/packages/swc) |\n| ---------------------------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |\n| `minify` your bundle in one pass[^1]           | ✅                                                                       | 🛑                                                                             | 🛑                                                                                   | 🛑                                                                                |\n| Standalone `swcMinify` plugin                  | ✅                                                                       | 🛑                                                                             | 🛑                                                                                   | 🛑                                                                                |\n| Config Intellisense[^2]                        | ✅                                                                       | 🛑                                                                             | 🛑                                                                                   | 🛑                                                                                |\n| Reads your `tsconfig.json` and `jsconfig.json` | ✅                                                                       | 🛑                                                                             | 🛑                                                                                   | 🛑                                                                                |\n| ESM export                                     | ✅                                                                       | 🟡[^3]                                                                         | 🛑                                                                                   | ✅                                                                                |\n| TypeScript declarations                         | ✅                                                                       | ✅                                                                             | ✅                                                                                   | ✅                                                                                |\n| Has testing                                    | ✅                                                                       | 🛑                                                                             | 🛑                                                                                   | ✅                                                                                |\n\n[^1]: If minify is called in Rollup's `transform` phase, every individual module processed will result in a minify call. However, if minify is called in Rollup's `renderChunk` phase, the minify will only be called once in one whole pass before Rollup generates bundle, results in a faster build.\n[^2]: Autocompletion and type checking in your IDE\n[^3]: `mentaljam/rollup-plugin-swc` has both `main` and `module` fields in `package.json`, but has🛑`exports` field.\n\n## Install\n\n```bash\n$ npm i @swc/core rollup-plugin-swc3\n# If you prefer yarn\n# yarn add @swc/core rollup-plugin-swc3\n# If you prefer pnpm\n# pnpm add @swc/core rollup-plugin-swc3\n```\n\n## Usage\n\n```js\n// rollup.config.js\nimport { swc } from 'rollup-plugin-swc3';\n\nexport default {\n  input: 'xxxx',\n  output: {},\n  plugins: [\n    swc({\n      // All options are optional\n      include: /\\.[mc]?[jt]sx?$/, // default\n      exclude: /node_modules/, // default\n      tsconfig: 'tsconfig.json', // default\n      // tsconfig: false, // You can also prevent `rollup-plugin-swc` from reading tsconfig.json, see below\n      // And add your swc configuration here!\n      // \"filename\" will be ignored since it is handled by rollup\n      jsc: {}\n    }),\n  ];\n}\n```\n\nIf you want autocompletion in your IDE or type check:\n\n```js\nimport { swc, defineRollupSwcOption } from 'rollup-plugin-swc3';\n\nexport default {\n  input: 'xxxx',\n  output: {},\n  plugins: [\n    swc(defineRollupSwcOption({\n      // ... There goes the plugin's configuration\n    })),\n  ];\n}\n\n// or\n/** @type {import('rollup-plugin-swc3').PluginOptions} */\nconst swcPluginConfig = {}\n```\n\n### `exclude`\n\n- Type: `string | RegExp | Array\u003cString | RegExp\u003e`\n- Default: `/node_modules/`\n\nA [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should *ignore*.\n\n### `extensions`\n\n- Type: `string[]`\n- Default: `['.ts', '.tsx', '.mjs', '.js', '.cjs', '.jsx']`\n\nSpecifies the files in the build the plugin should operate on. Also, the plugin will search and resolve files for extensions in the order specified for extensionless imports.\n\n### `include`\n\n- Type: `string | RegExp | Array\u003cString | RegExp\u003e`\n- Default: `/\\.[mc]?[jt]sx?$/`\n\nA [picomatch pattern](https://github.com/micromatch/picomatch), or array of patterns, which specifies the files in the build the plugin should operate on.\n\n### `tsconfig`\n\n- Type: `string | false | undefined`\n- Default: `'tsconfig.json'`\n\n`rollup-plugin-swc` will read your `tsconfig.json` or [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) for default values if your doesn't provide corresponding swc options:\n\n- The configuration your passed to `rollup-plugin-swc` will always have the highest priority (higher than `tsconfig.json`/`jsconfig.json`).\n- `rollup-plugin-swc` uses [`get-tsconfig`](https://www.npmjs.com/package/get-tsconfig) to find the `tsconfig.json`/`jsconfig.json` for the file currently being transpiled.\n  - You can also provide a custom filename (E.g. `tsconfig.rollup.json`, `jsconfig.compile.json`) to `tsconfig` option, and `rollup-plugin-swc` will find and resolve the *nearest* file with that filename.\n  - You can also provide an absolute path (E.g. `/path/to/your/tsconfig.json`) to `tsconfig` option, and `rollup-plugin-swc` will only use the provided path as a single source of truth.\n- You can prevent `rollup-plugin-swc` from reading `tsconfig.json`/`jsconfig.json` by setting `tsconfig` option to `false`.\n- `jsconfig.json` will be ignored if `tsconfig.json` and `jsconfig.json` both exist.\n- The `extends` of `tsconfig.json`/`jsconfig.json` is ~~not supported~~ now supported.\n- `compilerOptions.target` will be passed to swc's `jsc.target`.\n- `compilerOptions.jsxImportSource`, `compilerOptions.jsxFactory`, and `compilerOptions.jsxFragmentFactory` will be passed to swc's `jsc.transform.react.importSource`, `jsc.transform.react.pragma` and `jsc.transform.react.pragmaFrag`.\n- When `compilerOptions.jsx` is either `react-jsx` or `react-jsxdev`, swc's `jsc.transform.react.runtime` will be `automatic`, otherwise it will be `classic`.\n  - `compilerOptions.jsx: react-jsxdev` will also set swc's `jsc.transform.react.development` to `true`.\n  - `compilerOptions.jsx: preserve` will be ignored. swc will always transpile your jsx into javascript code.\n- `compilerOptions.baseUrl` and `compilerOptions.paths` will be passed to swc's `jsc.baseUrl` and `jsc.paths` directly. They won't affect how rollup resolve your imports. If you have encounted any issue during bundling, please use other plugins to resolve your imports' aliases (e.g., add [rollup-plugin-typescript-paths](https://www.npmjs.com/package/rollup-plugin-typescript-paths) or [rollup-plugin-tsconfig-paths](https://www.npmjs.com/package/rollup-plugin-tsconfig-paths) before `@rollup/plugin-node-resolve`).\n- `compilerOptions.importHelpers` will be passed to swc's `jsc.externalHelpers`. You will have to have `@swc/helpers` avaliable in your project when enabled.\n- `compilerOptions.experimentalDecorators` and `compilerOptions.emitDecoratorMetadata` will be passed to swc's `jsc.parser.decorators` and `jsc.transform.decoratorMetadata`.\n- `compilerOptions.esModuleInterop` will always be **ignored**, as swc requires `module.type` to exist when `module.noInterop` is given.\n\n### Standalone Minify Plugin\n\nIf you only want to use `swc` to minify your bundle:\n\n```js\nimport { minify } from 'rollup-plugin-swc3'\n\nexport default {\n  plugins: [\n    minify({\n      // swc's minify option here\n      // mangle: {}\n      // compress: {}\n    }),\n  ],\n}\n```\n\nIf you want autocompletion in your IDE or type check:\n\n```js\nimport { minify, defineRollupSwcMinifyOption } from 'rollup-plugin-swc3'\n\nexport default {\n  plugins: [\n    minify(\n      defineRollupSwcMinifyOption({\n        // swc's minify option here\n        // mangle: {}\n        // compress: {}\n      })\n    ),\n  ],\n}\n\n// or\n/** @type {import('@swc/core').JsMinifyOptions} */\nconst swcMinifyConfig = {}\n```\n\nIf you are are using Vite and you do not want to use `terser` or `esbuild` for minification, `rollup-plugin-swc3` also provides a standalone minify plugin designed for Vite:\n\n```js\nimport { defineConfig } from 'vite';\nimport { viteMinify } from 'rollup-plugin-swc3'\n\nexport default defineConfig({\n  plugins: [\n    viteMinify({\n      // swc's minify option here\n      // mangle: {}\n      // compress: {}\n    }),\n  ],\n})\n```\n\n### React Server Component directives (`'use client'` and `'use server'`)\n\n~~Since version `0.9.0`, the support for `'use client'` and `'use server'` has been added:~~\n\n\u003e The support for `'use client'` and `'use server'` has been separated into a standalone rollup plugin [`rollup-preserve-directives`](https://github.com/huozhi/rollup-preserve-directives), maintained by [@huozhi](https://github.com/huozhi) and me. The previous `preserveUseDirective` named export is retained for the backward compatibility.\n\n```bash\n# npm\nnpm install -D rollup-preserve-directives\n# yarn\nyarn add -D rollup-preserve-directives\n# pnpm\npnpm add -D rollup-preserve-directives\n```\n\n```js\n// rollup.config.js\nimport { swc } from 'rollup-plugin-swc3';\nimport preserveDirectives from 'rollup-preserve-directives';\n\nexport default {\n  input: 'xxxx',\n  output: {},\n  plugins: [\n    swc(),\n    // And add `preserveDirectives` plugin after the `swc` plugin\n    preserveDirectives()\n  ];\n}\n```\n\nAnd that is it!\n\n`preserveDirectives` supports:\n\n- Merging duplicated directives in the output bundles\n\n  ```js\n  // src/foo.js\n  'use sukka';\n  'use foxtail';\n\n  export const foo = 'foo';\n\n  // src/bar.js\n  'use sukka';\n  export const bar = 'bar';\n\n  // src/index.js\n  export { foo } from './foo';\n  export { bar } from './bar';\n\n  // rollup.config.js\n  export default {\n    input: 'src/index.js',\n    output: { file: 'dist/index.js' }\n    plugins: [swc(), preserveDirectives()]\n  }\n\n  // dist/index.js\n  'use sukka';\n  'use foxtail';\n\n  const foo = 'foo';\n  const bar = 'bar';\n\n  export { foo, bar };\n  ```\n\n- When bundle React Client Component and React Server Component separately, mutiple entries will have their own separated and correct directives:\n\n  ```js\n  // src/client.js\n  'use client';\n  import { useState } from 'react';\n  export const Foo = () =\u003e { useState('client-only code') };\n\n  // src/server.js\n  'use server';\n  import 'fs';\n  export const bar = 'server only code';\n\n  // rollup.config.js\n  export default {\n    // let rollup bundle client and server separately by adding two entries\n    input: {\n      client: 'src/client.js',\n      server: 'src/server.js'\n    },\n    // output both client bundle and server bundle in the \"dist/\" directory\n    output: { dir: 'dist/', entryFileName: '[name].js' }\n    plugins: [swc(), preserveDirectives()]\n  }\n\n  // dist/client.js\n  'use client';\n  import { useState } from 'react';\n  const Foo = () =\u003e { useState('client-only code') };\n  export { Foo };\n\n  // dist/server.js\n  'use server';\n  import 'fs';\n  const bar = 'server only code';\n  export { bar };\n  ```\n\n### Write your Rollup config in TypeScript\n\nYou can write your Rollup config file in `rollup.config.ts`, and use the following command:\n\n```sh\nrollup --config rollup.config.ts --configPlugin swc3\n```\n\n### TypeScript Declaration File\n\nThere are serveral ways to generate declaration file:\n\n- Use `tsc` with `emitDeclarationOnly`, the slowest way but you get type checking, it doesn't bundle the `.d.ts` files.\n- Use `rollup-plugin-dts` which generates and bundle `.d.ts`, also does type checking. It is used by this plugin as well.\n\n### Use with Non-react JSX\n\nYou can either configure it in your `tsconfig.json` or in your `rollup.config.js`.\n\n```js\n// Vue JSX\nimport { swc, defineRollupSwcOption } from 'rollup-plugin-swc3';\n\nexport default {\n  input: 'xxxx',\n  output: {},\n  plugins: [\n    swc(defineRollupSwcOption({\n      jsc: {\n        experimental: {\n          plugins: [['swc-plugin-vue-jsx', {}]] // npm i swc-plugin-vue-jsx\n        }\n      }\n    })),\n  ];\n}\n```\n\n```js\n// Preact\nimport { swc, defineRollupSwcOption } from 'rollup-plugin-swc3';\n\nexport default {\n  input: 'xxxx',\n  output: {},\n  plugins: [\n    swc(defineRollupSwcOption({\n      jsc: {\n        transform:{\n          react: {\n          pragma: 'h',\n          pragmaFrag: 'Fragment'\n          // To use preact/jsx-runtime:\n          // importSource: 'preact',\n          // runtime: 'automatic'\n          }\n        }\n      }\n    })),\n  ];\n}\n```\n\n---\n\n**rollup-plugin-swc** © [Sukka](https://github.com/SukkaW), Released under the [MIT](./LICENSE) License.\u003cbr\u003e\nInspired by [egoist](https://github.com/egoist)'s [rollup-plugin-esbuild](https://github.com/egoist/rollup-plugin-esbuild).\u003cbr\u003e\nAuthored and maintained by Sukka with help from contributors ([list](https://github.com/SukkaW/rollup-plugin-swc/graphs/contributors)).\n\n\u003e [Personal Website](https://skk.moe) · [Blog](https://blog.skk.moe) · GitHub [@SukkaW](https://github.com/SukkaW) · Telegram Channel [@SukkaChannel](https://t.me/SukkaChannel) · Mastodon [@sukka@acg.mn](https://acg.mn/@sukka) · Twitter [@isukkaw](https://twitter.com/isukkaw) · Keybase [@sukka](https://keybase.io/sukka)\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/sponsors/SukkaW/\"\u003e\n    \u003cimg src=\"https://sponsor.cdn.skk.moe/sponsors.svg\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukkaw%2Frollup-plugin-swc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsukkaw%2Frollup-plugin-swc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukkaw%2Frollup-plugin-swc/lists"}