swc-plugin-react-compiler 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Geunhyeok LEE
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,181 @@
1
+ # swc-plugin-react-compiler
2
+
3
+ SWC Wasm plugin that runs the Rust port of React Compiler through SWC.
4
+
5
+ ![Preview](./preview.png)
6
+
7
+ ## Important Notice
8
+
9
+ This is **not** an official React plugin.
10
+
11
+ This package builds a SWC Wasm plugin around the Rust React Compiler work that is
12
+ currently being developed in the React repository. It is experimental, tracks
13
+ internal compiler APIs, and may break as the upstream Rust port changes.
14
+
15
+ Use it when you want to try the Rust React Compiler path with SWC today. Do not
16
+ treat it as a production-supported replacement for an official React Compiler
17
+ integration.
18
+
19
+ ## Install
20
+
21
+ Install the plugin with the package manager your app already uses.
22
+
23
+ ```sh
24
+ npm install -D swc-plugin-react-compiler
25
+ ```
26
+
27
+ ```sh
28
+ pnpm add -D swc-plugin-react-compiler
29
+ ```
30
+
31
+ ```sh
32
+ yarn add -D swc-plugin-react-compiler
33
+ ```
34
+
35
+ For Vite React apps using SWC, also install `@vitejs/plugin-react-swc` if it is
36
+ not already present.
37
+
38
+ ```sh
39
+ npm install -D @vitejs/plugin-react-swc
40
+ pnpm add -D @vitejs/plugin-react-swc
41
+ yarn add -D @vitejs/plugin-react-swc
42
+ ```
43
+
44
+ ## Vite Usage
45
+
46
+ The package exports the absolute path to the compiled Wasm plugin. Pass that
47
+ path to `@vitejs/plugin-react-swc`.
48
+
49
+ ```ts
50
+ // vite.config.ts
51
+ import react from '@vitejs/plugin-react-swc';
52
+ import { defineConfig } from 'vite';
53
+ import reactCompilerPlugin from 'swc-plugin-react-compiler';
54
+
55
+ export default defineConfig({
56
+ plugins: [
57
+ react({
58
+ plugins: [[reactCompilerPlugin, { compilationMode: 'all' }]],
59
+ }),
60
+ ],
61
+ });
62
+ ```
63
+
64
+ The options object is forwarded to the React Compiler plugin options. For quick
65
+ experiments, `compilationMode: 'all'` makes the transform easier to verify.
66
+
67
+ ## Direct SWC Usage
68
+
69
+ You can also pass the exported Wasm path directly to `@swc/core`.
70
+
71
+ ```ts
72
+ import { transform } from '@swc/core';
73
+ import reactCompilerPlugin from 'swc-plugin-react-compiler';
74
+
75
+ const result = await transform(source, {
76
+ filename: 'Component.tsx',
77
+ jsc: {
78
+ parser: {
79
+ syntax: 'typescript',
80
+ tsx: true,
81
+ },
82
+ target: 'es2022',
83
+ experimental: {
84
+ plugins: [[reactCompilerPlugin, { compilationMode: 'all' }]],
85
+ },
86
+ },
87
+ });
88
+
89
+ console.log(result.code);
90
+ ```
91
+
92
+ ## Current Constraints
93
+
94
+ - This package is experimental and unofficial.
95
+ - The Rust implementation is pulled from the React repository and wrapped as a
96
+ SWC Wasm plugin.
97
+ - The SWC plugin is built against the SWC versions required by the upstream
98
+ `react_compiler_swc` crate.
99
+ - The transform expects SWC plugin metadata to provide the original source text.
100
+ If source text cannot be read from the source map, the plugin leaves the module
101
+ unchanged.
102
+ - Transformed output may import `react/compiler-runtime`, so the consuming app
103
+ must use a React version that provides that runtime entry.
104
+
105
+ ## Repository Layout
106
+
107
+ ```text
108
+ .
109
+ ├── crates/swc-plugin-react-compiler/ # Rust SWC Wasm plugin
110
+ ├── src/ # JS package entry that exports the Wasm path
111
+ ├── example/ # Vite TODO app using the plugin
112
+ ├── Cargo.toml # Rust workspace
113
+ ├── package.json # JS workspace
114
+ ├── justfile # Development tasks
115
+ └── mise.toml # Tool versions
116
+ ```
117
+
118
+ ## Development
119
+
120
+ This repository uses `mise` for local tool versions and Yarn 4 with PnP.
121
+
122
+ Install the configured tools:
123
+
124
+ ```sh
125
+ mise install
126
+ ```
127
+
128
+ Set up the workspace:
129
+
130
+ ```sh
131
+ mise exec -- just setup
132
+ ```
133
+
134
+ Build the Wasm plugin:
135
+
136
+ ```sh
137
+ npm run build
138
+ ```
139
+
140
+ Run all checks:
141
+
142
+ ```sh
143
+ npm run check
144
+ ```
145
+
146
+ Run tests:
147
+
148
+ ```sh
149
+ npm run test
150
+ ```
151
+
152
+ Build the Vite example:
153
+
154
+ ```sh
155
+ npm run example
156
+ ```
157
+
158
+ Run the Vite example in development mode:
159
+
160
+ ```sh
161
+ mise exec -- just example-dev
162
+ ```
163
+
164
+ The dev server serves the TODO example at `http://127.0.0.1:5173/`.
165
+
166
+ ## Task Reference
167
+
168
+ The `justfile` defines the main development tasks:
169
+
170
+ ```sh
171
+ just build # Build the Wasm plugin and copy it to the package root
172
+ just check # cargo check, TypeScript, oxlint, and oxfmt
173
+ just test # Rust tests
174
+ just example # Build the Vite TODO example
175
+ just example-dev # Run the Vite TODO example locally
176
+ just format # Apply oxfmt
177
+ ```
178
+
179
+ ## License
180
+
181
+ MIT. See [LICENSE](./LICENSE).
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "swc-plugin-react-compiler",
3
+ "version": "0.0.0",
4
+ "workspaces": [
5
+ "example"
6
+ ],
7
+ "files": [
8
+ "./src",
9
+ "./swc_plugin_react_compiler.wasm"
10
+ ],
11
+ "type": "module",
12
+ "main": "src/index.cjs",
13
+ "module": "src/index.js",
14
+ "types": "src/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./src/index.js",
18
+ "require": "./src/index.cjs",
19
+ "types": "./src/index.d.ts"
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "scripts": {
24
+ "build": "mise exec -- just build",
25
+ "check": "mise exec -- just check",
26
+ "example": "mise exec -- just example",
27
+ "format": "mise exec -- just format",
28
+ "format:check": "mise exec -- just format-check",
29
+ "lint": "mise exec -- just lint",
30
+ "test": "mise exec -- just test",
31
+ "typecheck": "mise exec -- just typecheck"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^25.9.2",
35
+ "oxfmt": "^0.54.0",
36
+ "oxlint": "^1.69.0",
37
+ "typescript": "^6.0.3"
38
+ },
39
+ "dependenciesMeta": {
40
+ "oxfmt": {
41
+ "unplugged": true
42
+ },
43
+ "oxlint": {
44
+ "unplugged": true
45
+ }
46
+ },
47
+ "packageManager": "yarn@4.16.0"
48
+ }
package/src/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ const { resolve } = require('node:path');
2
+
3
+ module.exports = resolve(__dirname, '..', 'swc_plugin_react_compiler.wasm');
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const pluginPath: string;
2
+
3
+ export default pluginPath;
package/src/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { resolve } from 'node:path';
2
+
3
+ export default resolve(
4
+ import.meta.dirname,
5
+ '..',
6
+ 'swc_plugin_react_compiler.wasm',
7
+ );
Binary file