@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 CHANGED
@@ -1,34 +1,55 @@
1
1
  # @vureact/compiler-core
2
2
 
3
- **Write Vue, Ship Production-Ready React** — Build React 18+ apps with the Vue 3 mental model.
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
- [![Npm](https://img.shields.io/npm/v/@vureact/compiler-core.svg?label=Npm&style=flat-square)](https://vureact.top/en/)
6
10
  [![Downloads](https://img.shields.io/npm/dt/@vureact/compiler-core?label=Downloads&style=flat-square)](https://www.npmjs.com/package/@vureact/compiler-core)
7
- [![Monthly](https://img.shields.io/npm/dm/@vureact/compiler-core?label=Monthly&style=flat-square)](https://www.npmjs.com/package/@vureact/compiler-core)
8
11
  [![Node](https://img.shields.io/badge/node-%3E%3D19.0.0-green?label=Node)](https://nodejs.org/)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
- [![Vue 3](https://img.shields.io/badge/Vue-3.x-42b883)](https://vuejs.org/)
11
- [![React 18+](https://img.shields.io/badge/React-18%2B-61dafb)](https://reactjs.org/)
12
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/vureact-js/core/blob/master/LICENSE)
12
13
 
13
14
  English | [简体中文](./README.md)
14
15
 
15
- ## Introduction
16
+ ## Who this package is for
16
17
 
17
- `@vureact/compiler-core` is the core compilation package of VuReact, responsible for compiling Vue 3 SFC, script files, and style files into React 18+ JSX/TSX code ready for production.
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
- ## Installation
22
+ ## Usage
23
+
24
+ ### 1. Install
20
25
 
21
26
  ```bash
22
27
  npm install -D @vureact/compiler-core
23
28
  ```
24
29
 
25
- ## Quick Start
30
+ You can also use:
26
31
 
27
- 👉 **Full tutorial: [VuReact Website - Quick Start](https://vureact.top/en/guide/quick-start.html)**
32
+ ```bash
33
+ pnpm add -D @vureact/compiler-core
34
+ yarn add -D @vureact/compiler-core
35
+ ```
28
36
 
29
- ### Configuration Example
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
- ### Commands
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
- npx vureact build # Build project
51
- npx vureact watch # Watch mode
156
+ cd .vureact/react-app
157
+ npm install
158
+ npm run dev
52
159
  ```
53
160
 
54
- ## Ecosystem
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
- - **[VuReact Runtime Core](https://runtime.vureact.top/en)**: React-compatible implementations of Vue core APIs
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
- If necessary, you can choose [☣️ Mixed Coding](https://vureact.top/en/guide/mind-control-readme.html) to directly use the React ecosystem.
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
- ## FAQ
172
+ ## Related packages
62
173
 
63
- 👉 [FAQ](https://vureact.top/en/guide/faq.html)
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
- ## 🔗 Links
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
- - Documentation: <https://vureact.top/en>
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,交付生产级 React 代码** —— 让你在 Vue 3 心智下,编译出 React 18+ 应用的编译工具。
3
+ **写 Vue,生成可维护的 React。**
4
+
5
+ `@vureact/compiler-core` 是 VuReact 的 **CLI 与核心编译包**。
6
+ 它用于将 Vue 3 的 SFC、脚本和样式文件编译为 **纯 React 18+ 代码**,适合渐进式迁移,以及“保持 Vue 心智模型、输出 React 工程”的场景。
7
+
8
+ 它是 **编译时方案**,不是运行时桥接。
4
9
 
5
- [![Npm](https://img.shields.io/npm/v/@vureact/compiler-core.svg?label=Npm&style=flat-square)](https://vureact.top/)
6
10
  [![Downloads](https://img.shields.io/npm/dt/@vureact/compiler-core?label=Downloads&style=flat-square)](https://www.npmjs.com/package/@vureact/compiler-core)
7
- [![Monthly](https://img.shields.io/npm/dm/@vureact/compiler-core?label=Monthly&style=flat-square)](https://www.npmjs.com/package/@vureact/compiler-core)
8
11
  [![Node](https://img.shields.io/badge/node-%3E%3D19.0.0-green?label=Node)](https://nodejs.org/)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
- [![Vue 3](https://img.shields.io/badge/Vue-3.x-42b883)](https://vuejs.org/)
11
- [![React 18+](https://img.shields.io/badge/React-18%2B-61dafb)](https://reactjs.org/)
12
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/vureact-js/core/blob/master/LICENSE)
12
13
 
13
14
  简体中文 | [English](./README.en.md)
14
15
 
15
- ## 简介
16
+ ## 这个包适合谁
16
17
 
17
- `@vureact/compiler-core` VuReact 的核心编译包,负责将 Vue 3 单文件组件、脚本文件和样式文件**三位一体**编译为可直接用于生产环境的 React 18+ JSX/TSX 代码。
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
- 👉 **完整教程请访问:[VuReact - 快速开始](https://vureact.top/guide/quick-start.html)**
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
- npx vureact build # 编译项目
51
- npx vureact watch # 监听模式
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
- - **[VuReact Runtime Core](https://runtime.vureact.top/)**:提供 React 版的 Vue 常用内置组件、核心 Composition API
57
- - **[VuReact Router](https://router.vureact.top/)**:支持 Vue Router 4.x React Router DOM 7.9+ 转换
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
- 如果确实需要,你可以选择 [☣️混合编写](https://vureact.top/guide/mind-control-readme.html),以此直接使用 React 生态。
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
- 👉 请查阅[官网 FAQ 章节](https://vureact.top/guide/faq.html)
186
+ ## 仓库与许可证
64
187
 
65
- ## 🔗 链接
188
+ - GitHub: <https://github.com/vureact-js/core>
189
+ - 文档: <https://vureact.top>
66
190
 
67
- - GitHub:<https://github.com/vureact-js/core>
68
- - Gitee:<https://gitee.com/vureact-js/core>
69
- - 文档:<https://vureact.top>
191
+ MIT License © 2025 Ruihong Zhong (Ryan John)