swc-plugin-react-compiler
v0.1.2
Published
SWC plugin for the Rust React Compiler port
Downloads
608
Readme
swc-plugin-react-compiler
SWC plugin that runs the Rust port of React Compiler through SWC.

[!NOTE] This is an unofficial plugin built to use the Rust port of React Compiler with SWC before an official SWC integration is available.
Install
Install the plugin with the package manager your app already uses.
npm install -D swc-plugin-react-compilerpnpm add -D swc-plugin-react-compileryarn add -D swc-plugin-react-compilerVite Usage
The package exports the absolute path to the compiled Wasm plugin. Pass that path to @vitejs/plugin-react-swc.
// vite.config.ts
import react from '@vitejs/plugin-react-swc';
import { defineConfig } from 'vite';
import reactCompilerPlugin from 'swc-plugin-react-compiler';
export default defineConfig({
plugins: [
react({
plugins: [[reactCompilerPlugin, { compilationMode: 'all' }]],
}),
],
});The options object is forwarded to the React Compiler plugin options. For quick experiments, compilationMode: 'all' makes the transform easier to verify.
SWC Usage
You can also pass the exported Wasm path directly to @swc/core.
import { transform } from '@swc/core';
import reactCompilerPlugin from 'swc-plugin-react-compiler';
const result = await transform(source, {
filename: 'Component.tsx',
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
target: 'es2022',
experimental: {
plugins: [[reactCompilerPlugin, { compilationMode: 'all' }]],
},
},
});
console.log(result.code);Development
This repository uses mise.
Install the configured tools:
mise installSet up the workspace:
mise exec -- just setupBuild the plugin:
npm run buildRun tests:
npm run testRun all checks:
npm run checkRun the Vite example in development mode:
mise exec -- just exampleThe dev server serves the TODO example at http://127.0.0.1:5173/.
Task Reference
The justfile defines the main development tasks:
just build # Build the Wasm plugin and copy it to the package root
just check # cargo check, typecheck, oxlint, and oxfmt
just format # Apply oxfmt
just test # Rust tests
just example # Run the Vite TODO example locally