@vureact/compiler-core 1.7.0 → 1.8.1
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/README.en.md +148 -24
- package/README.md +148 -26
- package/lib/{chunk-Q7HZAZHD.esm.js → chunk-QXYYGKFW.esm.js} +645 -549
- package/lib/{chunk-Q36XF5TP.js → chunk-SGP2JC7F.js} +666 -570
- package/lib/cli.esm.js +3 -2
- package/lib/cli.js +11 -10
- package/lib/compiler-core.d.cts +72 -57
- package/lib/compiler-core.d.ts +72 -57
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +7 -6
package/README.en.md
CHANGED
|
@@ -1,34 +1,55 @@
|
|
|
1
1
|
# @vureact/compiler-core
|
|
2
2
|
|
|
3
|
-
**Write Vue,
|
|
3
|
+
**Write in Vue, generate maintainable React.**
|
|
4
|
+
|
|
5
|
+
`@vureact/compiler-core` is the **CLI and core compiler package** of VuReact.
|
|
6
|
+
It compiles Vue 3 SFC, script, and style files into **pure React 18+ code**, making it suitable for progressive migration and for teams that want to keep Vue authoring conventions while targeting a React app.
|
|
7
|
+
|
|
8
|
+
It is a **compile-time solution**, not a runtime bridge.
|
|
4
9
|
|
|
5
|
-
[](https://vureact.top/en/)
|
|
6
10
|
[](https://www.npmjs.com/package/@vureact/compiler-core)
|
|
7
|
-
[](https://www.npmjs.com/package/@vureact/compiler-core)
|
|
8
11
|
[](https://nodejs.org/)
|
|
9
|
-
[](https://
|
|
10
|
-
[](https://vuejs.org/)
|
|
11
|
-
[](https://reactjs.org/)
|
|
12
|
+
[](https://github.com/vureact-js/core/blob/master/LICENSE)
|
|
12
13
|
|
|
13
14
|
English | [简体中文](./README.md)
|
|
14
15
|
|
|
15
|
-
##
|
|
16
|
+
## Who this package is for
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
- Teams progressively migrating a Vue 3 codebase to React
|
|
19
|
+
- Developers who want Vue-style authoring with React output
|
|
20
|
+
- Projects that need a config-driven `build/watch` compilation workflow
|
|
18
21
|
|
|
19
|
-
##
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### 1. Install
|
|
20
25
|
|
|
21
26
|
```bash
|
|
22
27
|
npm install -D @vureact/compiler-core
|
|
23
28
|
```
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
You can also use:
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
```bash
|
|
33
|
+
pnpm add -D @vureact/compiler-core
|
|
34
|
+
yarn add -D @vureact/compiler-core
|
|
35
|
+
```
|
|
28
36
|
|
|
29
|
-
###
|
|
37
|
+
### 2. Create a config file
|
|
30
38
|
|
|
31
|
-
`vureact.config.ts`
|
|
39
|
+
Create `vureact.config.ts` in your project root:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { defineConfig } from '@vureact/compiler-core';
|
|
43
|
+
|
|
44
|
+
export default defineConfig({
|
|
45
|
+
input: '', // input path: a single file or a directory
|
|
46
|
+
exclude: ['src/main.ts'], // exclude the Vue entry file
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
If you are fine with the default workspace and output directory, this is enough.
|
|
51
|
+
|
|
52
|
+
If you want to make the output settings explicit, you can write:
|
|
32
53
|
|
|
33
54
|
```ts
|
|
34
55
|
import { defineConfig } from '@vureact/compiler-core';
|
|
@@ -44,25 +65,128 @@ export default defineConfig({
|
|
|
44
65
|
});
|
|
45
66
|
```
|
|
46
67
|
|
|
47
|
-
|
|
68
|
+
If your project uses Vue Router, you will usually also add:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
router: {
|
|
72
|
+
configFile: 'src/router/index.ts',
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Start with a single-file pilot
|
|
77
|
+
|
|
78
|
+
If you want to validate the transformation first, start with one SFC:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
export default defineConfig({
|
|
82
|
+
input: './src/your-component.vue',
|
|
83
|
+
exclude: ['src/main.ts'],
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
This is useful when you want to:
|
|
88
|
+
|
|
89
|
+
- validate the compilation conventions first
|
|
90
|
+
- inspect the generated output first
|
|
91
|
+
- run a small pilot before scaling to the whole codebase
|
|
92
|
+
|
|
93
|
+
### 4. Expand to the whole project
|
|
94
|
+
|
|
95
|
+
Once the single-file pilot works, point `input` to a directory:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
export default defineConfig({
|
|
99
|
+
input: './src',
|
|
100
|
+
exclude: ['src/main.ts'],
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
This will recursively process Vue, script, and style files under that directory.
|
|
105
|
+
|
|
106
|
+
> Note: VuReact primarily targets modern Vue 3 codebases built around `<script setup>`.
|
|
107
|
+
> If your project uses Vue Router, also see the [router adaptation guide](https://vureact.top/en/guide/router-adaptation.html).
|
|
108
|
+
|
|
109
|
+
### 5. Run the compiler
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# one-time build
|
|
113
|
+
npx vureact build
|
|
114
|
+
|
|
115
|
+
# watch mode
|
|
116
|
+
npx vureact watch
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
If you prefer scripts, add them to `package.json`:
|
|
120
|
+
|
|
121
|
+
```json
|
|
122
|
+
{
|
|
123
|
+
"scripts": {
|
|
124
|
+
"vr:build": "vureact build",
|
|
125
|
+
"vr:watch": "vureact watch"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 6. Check the output
|
|
131
|
+
|
|
132
|
+
By default, VuReact generates:
|
|
133
|
+
|
|
134
|
+
- `.vureact/cache` for compilation cache
|
|
135
|
+
- `.vureact/react-app` for the React app output
|
|
136
|
+
- `.tsx` / `.css` files that mirror your source structure
|
|
137
|
+
|
|
138
|
+
The project layout typically looks like:
|
|
139
|
+
|
|
140
|
+
```txt
|
|
141
|
+
vue-project/
|
|
142
|
+
├── .vureact/
|
|
143
|
+
│ ├── cache/
|
|
144
|
+
│ ├── react-app/
|
|
145
|
+
│ │ ├── src/
|
|
146
|
+
│ │ ├── package.json
|
|
147
|
+
│ │ ├── vite.config.ts
|
|
148
|
+
├── src/
|
|
149
|
+
├── package.json
|
|
150
|
+
└── vureact.config.ts
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You can then run the generated app directly:
|
|
48
154
|
|
|
49
155
|
```bash
|
|
50
|
-
|
|
51
|
-
|
|
156
|
+
cd .vureact/react-app
|
|
157
|
+
npm install
|
|
158
|
+
npm run dev
|
|
52
159
|
```
|
|
53
160
|
|
|
54
|
-
|
|
161
|
+
If you want a deeper explanation of the two modes, continue with:
|
|
162
|
+
|
|
163
|
+
- [Watch Mode](https://vureact.top/en/guide/watch-mode.html)
|
|
164
|
+
- [Incremental Compilation](https://vureact.top/en/guide/incremental-compilation.html)
|
|
55
165
|
|
|
56
|
-
|
|
57
|
-
- **[VuReact Router](https://router.vureact.top/en)**: Vue Router 4.x → React Router DOM 7.9+ conversion
|
|
166
|
+
## What this package is not
|
|
58
167
|
|
|
59
|
-
|
|
168
|
+
- It is not a Vue-in-React / React-in-Vue runtime bridge
|
|
169
|
+
- It is not a zero-convention codemod for arbitrary Vue code
|
|
170
|
+
- It works best in projects that follow VuReact compilation conventions
|
|
60
171
|
|
|
61
|
-
##
|
|
172
|
+
## Related packages
|
|
62
173
|
|
|
63
|
-
|
|
174
|
+
- [@vureact/runtime-core](https://runtime.vureact.top/en/) - React-side Vue runtime adaptation APIs
|
|
175
|
+
- [@vureact/router](https://router.vureact.top/en/) - Vue Router to React Router adaptation
|
|
64
176
|
|
|
65
|
-
##
|
|
177
|
+
## Documentation
|
|
178
|
+
|
|
179
|
+
- [Quick Start](https://vureact.top/en/guide/quick-start.html)
|
|
180
|
+
- [Key Configuration](https://vureact.top/en/guide/key-configuration.html)
|
|
181
|
+
- [Watch Mode](https://vureact.top/en/guide/watch-mode.html)
|
|
182
|
+
- [Incremental Compilation](https://vureact.top/en/guide/incremental-compilation.html)
|
|
183
|
+
- [Progressive Migration Guide](https://vureact.top/en/guide/progressive-migration.html)
|
|
184
|
+
- [Config API](https://vureact.top/en/api/config.html)
|
|
185
|
+
- [FAQ](https://vureact.top/en/guide/faq.html)
|
|
186
|
+
|
|
187
|
+
## Repository and license
|
|
66
188
|
|
|
67
189
|
- GitHub: <https://github.com/vureact-js/core>
|
|
68
|
-
-
|
|
190
|
+
- Docs: <https://vureact.top/en>
|
|
191
|
+
|
|
192
|
+
MIT License © 2025 Ruihong Zhong (Ryan John)
|
package/README.md
CHANGED
|
@@ -1,34 +1,54 @@
|
|
|
1
1
|
# @vureact/compiler-core
|
|
2
2
|
|
|
3
|
-
**写 Vue
|
|
3
|
+
**写 Vue,生成可维护的 React。**
|
|
4
|
+
|
|
5
|
+
`@vureact/compiler-core` 是 VuReact 的 **CLI 与核心编译包**。
|
|
6
|
+
它用于将 Vue 3 的 SFC、脚本和样式文件编译为 **纯 React 18+ 代码**,适合渐进式迁移,以及“保持 Vue 心智模型、输出 React 工程”的场景。
|
|
7
|
+
|
|
8
|
+
它是 **编译时方案**,不是运行时桥接。
|
|
4
9
|
|
|
5
|
-
[](https://vureact.top/)
|
|
6
10
|
[](https://www.npmjs.com/package/@vureact/compiler-core)
|
|
7
|
-
[](https://www.npmjs.com/package/@vureact/compiler-core)
|
|
8
11
|
[](https://nodejs.org/)
|
|
9
|
-
[](https://
|
|
10
|
-
[](https://vuejs.org/)
|
|
11
|
-
[](https://reactjs.org/)
|
|
12
|
+
[](https://github.com/vureact-js/core/blob/master/LICENSE)
|
|
12
13
|
|
|
13
14
|
简体中文 | [English](./README.en.md)
|
|
14
15
|
|
|
15
|
-
##
|
|
16
|
+
## 这个包适合谁
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
- 正在把 Vue 3 项目渐进迁移到 React
|
|
19
|
+
- 想继续按 Vue 约定写代码,但产出 React 工程
|
|
20
|
+
- 需要基于配置文件执行 `build/watch` 编译流程
|
|
18
21
|
|
|
19
|
-
##
|
|
22
|
+
## 使用方式
|
|
23
|
+
|
|
24
|
+
### 1. 安装
|
|
20
25
|
|
|
21
26
|
```bash
|
|
22
27
|
npm install -D @vureact/compiler-core
|
|
23
28
|
```
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
也可以使用:
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
```bash
|
|
33
|
+
pnpm add -D @vureact/compiler-core
|
|
34
|
+
yarn add -D @vureact/compiler-core
|
|
35
|
+
```
|
|
28
36
|
|
|
29
|
-
###
|
|
37
|
+
### 2. 创建配置文件
|
|
30
38
|
|
|
31
|
-
`vureact.config.ts
|
|
39
|
+
在项目根目录新建 `vureact.config.ts`:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { defineConfig } from '@vureact/compiler-core';
|
|
43
|
+
|
|
44
|
+
export default defineConfig({
|
|
45
|
+
exclude: ['src/main.ts'], // 排除 Vue 入口文件
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
如果你只想用默认工作区和输出目录,这样就够了。
|
|
50
|
+
|
|
51
|
+
如果需要显式指定输出配置,可以写成:
|
|
32
52
|
|
|
33
53
|
```ts
|
|
34
54
|
import { defineConfig } from '@vureact/compiler-core';
|
|
@@ -44,26 +64,128 @@ export default defineConfig({
|
|
|
44
64
|
});
|
|
45
65
|
```
|
|
46
66
|
|
|
47
|
-
|
|
67
|
+
如果项目使用 Vue Router,通常还会补上:
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
router: {
|
|
71
|
+
configFile: 'src/router/index.ts',
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 3. 先从单文件试点
|
|
76
|
+
|
|
77
|
+
如果你想先验证一个组件能否稳定转换,可以先只编译单个 SFC:
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
export default defineConfig({
|
|
81
|
+
input: './src/your-component.vue',
|
|
82
|
+
exclude: ['src/main.ts'],
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
这适合:
|
|
87
|
+
|
|
88
|
+
- 先验证编译约定
|
|
89
|
+
- 先看生成结果
|
|
90
|
+
- 先小范围试点,而不是直接全仓推进
|
|
91
|
+
|
|
92
|
+
### 4. 再扩展到整个项目
|
|
93
|
+
|
|
94
|
+
当单文件试点通过后,再把 `input` 指向目录:
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
export default defineConfig({
|
|
98
|
+
input: './src',
|
|
99
|
+
exclude: ['src/main.ts'],
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
这会递归处理目录下的 Vue / Script / Style 文件。
|
|
104
|
+
|
|
105
|
+
> 注意:VuReact 优先支持基于 `<script setup>` 的现代 Vue 3 写法。
|
|
106
|
+
> 如果你的项目使用 Vue Router,请同时查看 [路由适配指南](https://vureact.top/guide/router-adaptation.html)。
|
|
107
|
+
|
|
108
|
+
### 5. 执行编译
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# 一次性编译
|
|
112
|
+
npx vureact build
|
|
113
|
+
|
|
114
|
+
# 监听模式
|
|
115
|
+
npx vureact watch
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
如果你更喜欢脚本命令,也可以写进 `package.json`:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"scripts": {
|
|
123
|
+
"vr:build": "vureact build",
|
|
124
|
+
"vr:watch": "vureact watch"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 6. 查看输出结果
|
|
130
|
+
|
|
131
|
+
默认情况下,VuReact 会生成:
|
|
132
|
+
|
|
133
|
+
- `.vureact/cache`:编译缓存
|
|
134
|
+
- `.vureact/react-app`:React 工程产物
|
|
135
|
+
- 与源目录结构对应的 `.tsx` / `.css` 文件
|
|
136
|
+
|
|
137
|
+
目录大致如下:
|
|
138
|
+
|
|
139
|
+
```txt
|
|
140
|
+
vue-project/
|
|
141
|
+
├── .vureact/
|
|
142
|
+
│ ├── cache/
|
|
143
|
+
│ ├── react-app/
|
|
144
|
+
│ │ ├── src/
|
|
145
|
+
│ │ ├── package.json
|
|
146
|
+
│ │ ├── vite.config.ts
|
|
147
|
+
├── src/
|
|
148
|
+
├── package.json
|
|
149
|
+
└── vureact.config.ts
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
进入产物目录后可直接运行:
|
|
48
153
|
|
|
49
154
|
```bash
|
|
50
|
-
|
|
51
|
-
|
|
155
|
+
cd .vureact/react-app
|
|
156
|
+
npm install
|
|
157
|
+
npm run dev
|
|
52
158
|
```
|
|
53
159
|
|
|
54
|
-
|
|
160
|
+
如果你想更系统地了解 build/watch 的差异,可以继续阅读:
|
|
161
|
+
|
|
162
|
+
- [监听模式](https://vureact.top/guide/watch-mode.html)
|
|
163
|
+
- [增量编译](https://vureact.top/guide/incremental-compilation.html)
|
|
164
|
+
|
|
165
|
+
## 这个包不负责什么
|
|
166
|
+
|
|
167
|
+
- 它不是 Vue in React / React in Vue 的运行时桥接层
|
|
168
|
+
- 它不是对任意 Vue 代码都“零约定”生效的通用 codemod
|
|
169
|
+
- 它更适合遵循 VuReact 编译约定的工程化项目
|
|
170
|
+
|
|
171
|
+
## 相关包
|
|
55
172
|
|
|
56
|
-
-
|
|
57
|
-
-
|
|
173
|
+
- [@vureact/runtime-core](https://runtime.vureact.top/):React 版 Vue 运行时适配 API
|
|
174
|
+
- [@vureact/router](https://router.vureact.top/):Vue Router 到 React Router 的适配方案
|
|
58
175
|
|
|
59
|
-
|
|
176
|
+
## 文档入口
|
|
60
177
|
|
|
61
|
-
|
|
178
|
+
- [快速开始](https://vureact.top/guide/quick-start.html)
|
|
179
|
+
- [关键配置](https://vureact.top/guide/key-configuration.html)
|
|
180
|
+
- [监听模式](https://vureact.top/guide/watch-mode.html)
|
|
181
|
+
- [增量编译](https://vureact.top/guide/incremental-compilation.html)
|
|
182
|
+
- [渐进式迁移指南](https://vureact.top/guide/progressive-migration.html)
|
|
183
|
+
- [配置 API](https://vureact.top/api/config.html)
|
|
184
|
+
- [FAQ](https://vureact.top/guide/faq.html)
|
|
62
185
|
|
|
63
|
-
|
|
186
|
+
## 仓库与许可证
|
|
64
187
|
|
|
65
|
-
|
|
188
|
+
- GitHub: <https://github.com/vureact-js/core>
|
|
189
|
+
- 文档: <https://vureact.top>
|
|
66
190
|
|
|
67
|
-
|
|
68
|
-
- Gitee:<https://gitee.com/vureact-js/core>
|
|
69
|
-
- 文档:<https://vureact.top>
|
|
191
|
+
MIT License © 2025 Ruihong Zhong (Ryan John)
|