A plugin for legacy environments.
OXC does not support downleveling modern JavaScript syntax to ES5 and other legacy ECMAScript targets. As a result, applications built with Rolldown or Vite may not run correctly in older environments.
This plugin integrates SWC to transform and minify code for older ECMAScript targets. It includes several built-in presets and targets ES5 by default.
Currently, the plugin is distributed as an unplugin adapter and works with both Rolldown and Vite.
Install this package as a dependency in the project:
# npm
npm i unplugin-compat
# Yarn
yarn add unplugin-compat
# pnpm
pnpm add unplugin-compat
# Deno
deno add npm:unplugin-compat
# Bun
bun add unplugin-compatAdd the plugin into the Rolldown config:
import { defineConfig } from "rolldown";
import { compat } from "unplugin-compat/rolldown";
export default defineConfig({
input: "./src/index.ts",
plugins: [
compat(),
],
});Or add the plugin into the Vite config:
import { defineConfig } from "vite";
import { compat } from "unplugin-compat/vite";
export default defineConfig({
plugins: [
compat(),
],
});It is possible to use the plugin with presets:
import { defineConfig } from "rolldown";
import { compat, presets } from "unplugin-compat/rolldown";
export default defineConfig({
input: "./src/index.ts",
plugins: [
compat(presets.ES5),
],
});Or with minifiedPresets in Vite:
import { defineConfig } from "vite";
import { compat, minifiedPresets } from "unplugin-compat/vite";
export default defineConfig({
plugins: [
compat(minifiedPresets.ES3),
],
});The following tsconfig compilerOptions are automatically resolved and bound to transform options:
| Compiler Options | Transform Options |
|---|---|
jsx |
jsc.parser.jsx / jsc.parser.tsx |
jsxFactory |
jsc.transform.react.pragma |
jsxFragmentFactory |
jsc.transform.react.pragmaFrag |
jsxImportSource |
jsc.transform.react.importSource |
experimentalDecorators |
jsc.parser.decorators + jsc.keepClassNames + jsc.transform.legacyDecorator |
emitDecoratorMetadata |
jsc.transform.decoratorMetadata |
useDefineForClassFields |
jsc.transform.useDefineForClassFields |
For contributing, please refer to the contributing guide.
This project is licensed under the terms of the MIT license.