@vureact/compiler-core 1.3.0 → 1.5.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/README.en.md +286 -0
- package/README.md +76 -74
- package/lib/{chunk-CUCUXW56.esm.js → chunk-IGLKQRRZ.esm.js} +1084 -825
- package/lib/{chunk-7LBUUA24.js → chunk-TSGO73AO.js} +1123 -864
- package/lib/cli.esm.js +59 -47
- package/lib/cli.js +62 -50
- package/lib/compiler-core.d.cts +761 -1006
- package/lib/compiler-core.d.ts +761 -1006
- package/lib/compiler-core.esm.js +2 -2
- package/lib/compiler-core.js +3 -3
- package/package.json +13 -5
- package/README.zh.md +0 -284
- package/templates/route-setup-notes.md +0 -192
- package/templates/route-setup-notes.zh.md +0 -192
package/lib/compiler-core.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.5.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
parseOnlyScript,
|
|
19
19
|
parseSFC,
|
|
20
20
|
transform
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-IGLKQRRZ.esm.js";
|
|
22
22
|
export {
|
|
23
23
|
BaseCompiler,
|
|
24
24
|
CacheKey,
|
package/lib/compiler-core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});/**
|
|
2
|
-
* @vureact/compiler-core v1.
|
|
2
|
+
* @vureact/compiler-core v1.5.0
|
|
3
3
|
* (c) 2025-present Ruihong Zhong (Ryan John)
|
|
4
4
|
* @license MIT
|
|
5
5
|
*/
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkTSGO73AOjs = require('./chunk-TSGO73AO.js');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
@@ -33,4 +33,4 @@ var _chunk7LBUUA24js = require('./chunk-7LBUUA24.js');
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
exports.BaseCompiler =
|
|
36
|
+
exports.BaseCompiler = _chunkTSGO73AOjs.BaseCompiler; exports.CacheKey = _chunkTSGO73AOjs.CacheKey; exports.FileCompiler = _chunkTSGO73AOjs.FileCompiler; exports.Helper = _chunkTSGO73AOjs.Helper; exports.VuReact = _chunkTSGO73AOjs.VuReact; exports.defineConfig = _chunkTSGO73AOjs.defineConfig; exports.generate = _chunkTSGO73AOjs.generate; exports.generateComponent = _chunkTSGO73AOjs.generateComponent; exports.generateOnlyScript = _chunkTSGO73AOjs.generateOnlyScript; exports.parse = _chunkTSGO73AOjs.parse; exports.parseOnlyScript = _chunkTSGO73AOjs.parseOnlyScript; exports.parseSFC = _chunkTSGO73AOjs.parseSFC; exports.transform = _chunkTSGO73AOjs.transform;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vureact/compiler-core",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "🌀
|
|
3
|
+
"version": "1.5.0",
|
|
4
|
+
"description": "🌀 Semantic-aware Vue 3 to React 18+ compiler for progressive migration.",
|
|
5
5
|
"author": "Ruihong Zhong (Ryan John)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"bin",
|
|
20
|
-
"lib"
|
|
21
|
-
"templates"
|
|
20
|
+
"lib"
|
|
22
21
|
],
|
|
23
22
|
"keywords": [
|
|
24
23
|
"vue",
|
|
@@ -40,7 +39,14 @@
|
|
|
40
39
|
"vue3-to-react",
|
|
41
40
|
"vue-react",
|
|
42
41
|
"react-vue",
|
|
43
|
-
"vue-in-react"
|
|
42
|
+
"vue-in-react",
|
|
43
|
+
"code-migration",
|
|
44
|
+
"framework-migration",
|
|
45
|
+
"vue-migration",
|
|
46
|
+
"react-conversion",
|
|
47
|
+
"single-file-components",
|
|
48
|
+
"progressive-migration",
|
|
49
|
+
"automated-refactoring"
|
|
44
50
|
],
|
|
45
51
|
"homepage": "https://vureact.top",
|
|
46
52
|
"repository": {
|
|
@@ -81,7 +87,9 @@
|
|
|
81
87
|
"minimatch": "^10.1.1",
|
|
82
88
|
"ora": "^9.1.0",
|
|
83
89
|
"postcss": "^8.5.6",
|
|
90
|
+
"proper-lockfile": "^4.1.2",
|
|
84
91
|
"sass": "^1.97.3",
|
|
92
|
+
"tsx": "^4.21.0",
|
|
85
93
|
"update-notifier": "^7.3.1",
|
|
86
94
|
"xxhashjs": "^0.2.2"
|
|
87
95
|
},
|
package/README.zh.md
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
# @vureact/compiler-core
|
|
2
|
-
|
|
3
|
-
[](https://vureact.top/)
|
|
4
|
-
[](https://www.npmjs.com/package/@vureact/compiler-core)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
|
|
7
|
-
## 什么是 VuReact?
|
|
8
|
-
|
|
9
|
-
[VuReact](http://vureact.top)(发音 `/vjuːˈriːækt/`)是一个面向 Vue 3 → React 的智能编译工具链。
|
|
10
|
-
|
|
11
|
-
它不是简单的语法转换,而是**语义级编译**:理解 Vue 代码的意图,生成符合 React 最佳实践的代码。由**编译时转换** + **运行时适配**两部分构成。
|
|
12
|
-
|
|
13
|
-
核心策略是 **“约定优先”** ——通过明确的编译约定,确保转换稳定可靠,尤其适合**渐进式迁移**场景。
|
|
14
|
-
|
|
15
|
-
## 快速开始
|
|
16
|
-
|
|
17
|
-
本节将引导你完成第一个 VuReact 项目的创建、编译和运行;或者选择先查看 [在线示例。](https://codesandbox.io/p/sandbox/examples-f5rlpk)
|
|
18
|
-
|
|
19
|
-
完成后你会明确三件事:
|
|
20
|
-
|
|
21
|
-
1. 输入 SFC 在什么约定下可稳定转换
|
|
22
|
-
2. 编译后目录会长什么样
|
|
23
|
-
3. 输出 TSX 与原始 SFC 的语义对应关系
|
|
24
|
-
4. 编译器会自动分析并追加依赖,无需手动管理 React hooks 依赖项
|
|
25
|
-
|
|
26
|
-
## Step 0:准备目录
|
|
27
|
-
|
|
28
|
-
先准备一个最小工程(示意):
|
|
29
|
-
|
|
30
|
-
```txt
|
|
31
|
-
my-app/
|
|
32
|
-
├─ src/
|
|
33
|
-
│ ├─ components/
|
|
34
|
-
│ │ └─ Counter.vue
|
|
35
|
-
│ ├─ main.ts
|
|
36
|
-
│ └─ index.css
|
|
37
|
-
├─ package.json
|
|
38
|
-
└─ vureact.config.js
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## Step 1:安装
|
|
42
|
-
|
|
43
|
-
在你的 Vue 项目中安装 VuReact 编译器:
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
# 使用 npm
|
|
47
|
-
npm install -D @vureact/compiler-core
|
|
48
|
-
|
|
49
|
-
# 使用 yarn
|
|
50
|
-
yarn add -D @vureact/compiler-core
|
|
51
|
-
|
|
52
|
-
# 使用 pnpm
|
|
53
|
-
pnpm add -D @vureact/compiler-core
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Step 2:编写输入 SFC
|
|
57
|
-
|
|
58
|
-
`src/components/Counter.vue`
|
|
59
|
-
|
|
60
|
-
```html
|
|
61
|
-
<template>
|
|
62
|
-
<section class="counter-card">
|
|
63
|
-
<h2>{{ props.title || title }}</h2>
|
|
64
|
-
<p>Count: {{ count }}</p>
|
|
65
|
-
<button @click="increment">+1</button>
|
|
66
|
-
<button @click="methods.decrease">-1</button>
|
|
67
|
-
</section>
|
|
68
|
-
</template>
|
|
69
|
-
|
|
70
|
-
<script setup lang="ts">
|
|
71
|
-
// @vr-name: Counter (注:用于告诉编译器,该生成什么组件名)
|
|
72
|
-
import { computed, ref } from 'vue';
|
|
73
|
-
|
|
74
|
-
// 也可以使用宏定义组件名
|
|
75
|
-
defineOptions({ name: 'Counter' });
|
|
76
|
-
|
|
77
|
-
// 定义 props
|
|
78
|
-
const props = defineProps<{ title?: string }>();
|
|
79
|
-
|
|
80
|
-
// 定义 emits
|
|
81
|
-
const emits = defineEmits<{
|
|
82
|
-
(e: 'change'): void;
|
|
83
|
-
(e: 'update', value: number): number;
|
|
84
|
-
}>();
|
|
85
|
-
|
|
86
|
-
const step = ref(1);
|
|
87
|
-
const count = ref(0);
|
|
88
|
-
const title = computed(() => `Counter x${step.value}`);
|
|
89
|
-
|
|
90
|
-
const increment = () => {
|
|
91
|
-
count.value += step.value;
|
|
92
|
-
emits('update', count.value);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const methods = {
|
|
96
|
-
decrease() {
|
|
97
|
-
count.value -= step.value;
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
</script>
|
|
101
|
-
|
|
102
|
-
<style lang="less" scoped>
|
|
103
|
-
@border-color: #ddd;
|
|
104
|
-
@border-radius: 8px;
|
|
105
|
-
@padding-base: 12px;
|
|
106
|
-
|
|
107
|
-
.counter-card {
|
|
108
|
-
border: 1px solid @border-color;
|
|
109
|
-
border-radius: @border-radius;
|
|
110
|
-
padding: @padding-base;
|
|
111
|
-
}
|
|
112
|
-
</style>
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
## Step 3:配置编译器
|
|
116
|
-
|
|
117
|
-
`vureact.config.js`
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
import { defineConfig } from '@vureact/compiler-core';
|
|
121
|
-
|
|
122
|
-
export default defineConfig({
|
|
123
|
-
input: 'src',
|
|
124
|
-
// 关键:排除 Vue 入口文件,避免入口语义冲突
|
|
125
|
-
exclude: ['src/main.ts'],
|
|
126
|
-
output: {
|
|
127
|
-
workspace: '.vureact',
|
|
128
|
-
outDir: 'dist',
|
|
129
|
-
// 教程场景关闭环境初始化,便于观察纯编译产物
|
|
130
|
-
bootstrapVite: false,
|
|
131
|
-
},
|
|
132
|
-
format: {
|
|
133
|
-
enabled: true, // 开启格式化,同时这也会增加编译耗时。
|
|
134
|
-
formatter: 'prettier',
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
## Step 4:执行编译
|
|
140
|
-
|
|
141
|
-
### 方式一:使用 npx 命令
|
|
142
|
-
|
|
143
|
-
在根目录下运行:
|
|
144
|
-
|
|
145
|
-
```bash
|
|
146
|
-
npx vureact build
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### 方式二:使用 npm scripts
|
|
150
|
-
|
|
151
|
-
在 `package.json` 里添加脚本命令:
|
|
152
|
-
|
|
153
|
-
```json
|
|
154
|
-
"scripts": {
|
|
155
|
-
"watch": "vureact watch",
|
|
156
|
-
"build": "vureact build"
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
```bash
|
|
161
|
-
npm run build
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## Step 5:查看输出目录树
|
|
165
|
-
|
|
166
|
-
编译后目录(示意):
|
|
167
|
-
|
|
168
|
-
```txt
|
|
169
|
-
my-app/
|
|
170
|
-
├─ .vureact/
|
|
171
|
-
│ ├─ cache/
|
|
172
|
-
│ │ └─ _metadata.json
|
|
173
|
-
│ └─ dist/
|
|
174
|
-
│ └─ src/
|
|
175
|
-
│ └─ components/
|
|
176
|
-
│ ├─ Counter.tsx
|
|
177
|
-
│ └─ Counter-<hash>.css
|
|
178
|
-
├─ src/
|
|
179
|
-
│ └─ ...
|
|
180
|
-
└─ vureact.config.js
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
## Step 6:对照生成结果
|
|
184
|
-
|
|
185
|
-
下面是一个格式化后的典型输出(为说明做了轻微简化,实际哈希与属性名以本地产物为准):
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
import { memo, useCallback, useMemo } from 'react';
|
|
189
|
-
import { useComputed, useVRef } from '@vureact/runtime-core';
|
|
190
|
-
import './Counter-a1b2c3.css';
|
|
191
|
-
|
|
192
|
-
// 根据 defineProps 和 defineEmits 推导
|
|
193
|
-
type ICounterType = {
|
|
194
|
-
title?: string
|
|
195
|
-
onChange: () => void;
|
|
196
|
-
onUpdate: (value: number) => number;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// memo 包裹组件
|
|
200
|
-
const Counter = memo((props: ICounterType) => {
|
|
201
|
-
// ref/computed 转换成了对等的适配 API
|
|
202
|
-
const step = useVRef(1);
|
|
203
|
-
const count = useVRef(0);
|
|
204
|
-
const title = useComputed(() => `Counter x${step.value}`);
|
|
205
|
-
|
|
206
|
-
// 自动分析顶层箭头函数依赖,并追加 useCallback 优化
|
|
207
|
-
const increment = useCallback(() => {
|
|
208
|
-
count.value += step.value;
|
|
209
|
-
props.onUpdate?.(count.value); // emits 转换
|
|
210
|
-
}, [count.value, step.value, props.onUpdate]);
|
|
211
|
-
|
|
212
|
-
// 自动分析顶层对象中的依赖,并追加 useMemo 优化
|
|
213
|
-
const methods = useMemo(
|
|
214
|
-
() => ({
|
|
215
|
-
decrease() {
|
|
216
|
-
count.value -= step.value;
|
|
217
|
-
},
|
|
218
|
-
}),
|
|
219
|
-
[count.value, step.value],
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
return (
|
|
223
|
-
<>
|
|
224
|
-
<section className="counter-card" data-css-a1b2c3>
|
|
225
|
-
<h2 data-css-a1b2c3>{props.title || title.value}</h2>
|
|
226
|
-
<p data-css-a1b2c3>Count: {count.value}</p>
|
|
227
|
-
<button onClick={increment} data-css-a1b2c3>
|
|
228
|
-
+1
|
|
229
|
-
</button>
|
|
230
|
-
<button onClick={methods.decrease} data-css-a1b2c3>
|
|
231
|
-
-1
|
|
232
|
-
</button>
|
|
233
|
-
</section>
|
|
234
|
-
</>
|
|
235
|
-
);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
export default Counter;
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
CSS 文件内容:
|
|
242
|
-
|
|
243
|
-
```css
|
|
244
|
-
.counter-card[data-css-a1b2c3] {
|
|
245
|
-
border: 1px solid #ddd;
|
|
246
|
-
border-radius: 8px;
|
|
247
|
-
padding: 12px;
|
|
248
|
-
}
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
## 关键观察点
|
|
252
|
-
|
|
253
|
-
1. `// @vr-name: Counter` 这段特殊注释定义了组件名
|
|
254
|
-
2. `defineProps` 和 `defineEmits` 被转换成了 TS 组件类型
|
|
255
|
-
3. 非纯 UI 展示组件,默认会走 `memo` 包装
|
|
256
|
-
4. `ref` / `computed` 被转换为 runtime 适配 API(`useVRef` / `useComputed`)
|
|
257
|
-
5. 模板事件回调会生成符合 React 语义的 `onClick`
|
|
258
|
-
6. 顶层箭头函数自动分析依赖,尝试注入 `useCallback`
|
|
259
|
-
7. 顶层变量声明自动分析依赖,尝试注入 `useMemo`
|
|
260
|
-
8. 对 JSX 中的原 `ref` 状态值补上 `.value`
|
|
261
|
-
9. `less` 样式被编译为 css 代码
|
|
262
|
-
10. `scoped` 样式会生成带哈希的 css 文件,并在元素上标注作用域属性
|
|
263
|
-
|
|
264
|
-
## 常见失败点
|
|
265
|
-
|
|
266
|
-
- 没排除 Vue 入口文件,如 `src/main.ts` 或 `App.vue`
|
|
267
|
-
- 在非顶层调用会被转换为 Hook 的 API
|
|
268
|
-
- 模板里出现不可分析表达式并被告警
|
|
269
|
-
- 关闭样式预处理且使用 `scoped`,导致作用域失效
|
|
270
|
-
|
|
271
|
-
## 生态集成
|
|
272
|
-
|
|
273
|
-
- **[Vue 核心适配包](https://runtime.vureact.top/)**:提供 React 版的 Vue 常用内置组件、核心 Composition API 等
|
|
274
|
-
- **[Vue 路由适配包](https://router.vureact.top/)**:支持 Vue Router 4.x -> React Router DOM 7.9+ 转换
|
|
275
|
-
|
|
276
|
-
如果确实需要,你可以选择 [☣️混合编写](https://vureact.top/guide/mind-control-readme.html),以此直接使用 React 生态。
|
|
277
|
-
|
|
278
|
-
## 🔗 链接
|
|
279
|
-
|
|
280
|
-
- GitHub:<https://github.com/vureact-js/core>
|
|
281
|
-
- Gitee:<https://gitee.com/vureact-js/core>
|
|
282
|
-
- 文档:[https://vureact.top](https://vureact.top/)
|
|
283
|
-
- npm:<https://www.npmjs.com/package/@vureact/compiler-core>
|
|
284
|
-
- 在线示例:<https://codesandbox.io/p/devbox/compiler-examples-n8yg68>
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
# Router Adaptation Guide
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
VuReact provides full conversion support for Vue Router, but since routing is an engineering-level context, some manual adjustments are still required after compilation.
|
|
6
|
-
|
|
7
|
-
### Automatically Converted Parts
|
|
8
|
-
|
|
9
|
-
- `<router-link>` → `<RouterLink>`
|
|
10
|
-
- `<router-view>` → `<RouterView>`
|
|
11
|
-
- Routing API calls: `useRouter()`, `useRoute()`, etc.
|
|
12
|
-
- Automatically injects the `@vureact/router` dependency
|
|
13
|
-
|
|
14
|
-
### Parts Requiring Manual Adjustment
|
|
15
|
-
|
|
16
|
-
- Routing configuration file format conversion
|
|
17
|
-
- Entry file rendering method
|
|
18
|
-
- Exclusion configuration setup
|
|
19
|
-
|
|
20
|
-
## Configuration Steps
|
|
21
|
-
|
|
22
|
-
### Step 1: Preparation Before Compilation
|
|
23
|
-
|
|
24
|
-
Ensure your Vue project uses the standard Vue Router configuration.
|
|
25
|
-
|
|
26
|
-
### Step 2: Execute Compilation
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
npx vureact build
|
|
30
|
-
|
|
31
|
-
# Or manually configure the npm command
|
|
32
|
-
npm run vr:build
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Step 3: Adjust the Output React Project (Critical Step)
|
|
36
|
-
|
|
37
|
-
#### 3.1 Update the Entry File (src/main.tsx)
|
|
38
|
-
|
|
39
|
-
Example:
|
|
40
|
-
|
|
41
|
-
```tsx
|
|
42
|
-
import { StrictMode } from 'react';
|
|
43
|
-
import { createRoot } from 'react-dom/client';
|
|
44
|
-
import './index.css';
|
|
45
|
-
import router from './router';
|
|
46
|
-
|
|
47
|
-
createRoot(document.getElementById('root')!).render(
|
|
48
|
-
<StrictMode>
|
|
49
|
-
<router.RouterProvider />
|
|
50
|
-
</StrictMode>,
|
|
51
|
-
);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**Important Changes**:
|
|
55
|
-
|
|
56
|
-
- Import the Router Provider; there is no need to render `<App />` because `App` should be mounted in the routing configuration.
|
|
57
|
-
|
|
58
|
-
#### 3.2 Convert the Routing Configuration File
|
|
59
|
-
|
|
60
|
-
The actual structure shall be based on the routing configuration output by your project.
|
|
61
|
-
|
|
62
|
-
Rename `src/router/index.ts` to `src/router/index.tsx`.
|
|
63
|
-
|
|
64
|
-
Example:
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
import { createRouter, createWebHashHistory } from '@vureact/router';
|
|
68
|
-
import App from '../App';
|
|
69
|
-
import Dashboard from '../pages/Dashboard';
|
|
70
|
-
import Customers from '../pages/Customers';
|
|
71
|
-
|
|
72
|
-
const router = createRouter({
|
|
73
|
-
history: createWebHashHistory(),
|
|
74
|
-
routes: [
|
|
75
|
-
{
|
|
76
|
-
path: '/',
|
|
77
|
-
component: <App />,
|
|
78
|
-
children: [
|
|
79
|
-
{ path: 'dashboard', component: <Dashboard /> },
|
|
80
|
-
{ path: 'customers', component: <Customers /> },
|
|
81
|
-
],
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
export default router;
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**Important Changes**:
|
|
90
|
-
|
|
91
|
-
- File extension: `.ts` → `.tsx`
|
|
92
|
-
- Export the `createRouter` router instance
|
|
93
|
-
- Component syntax: `component: Dashboard` → `component: <Dashboard />`
|
|
94
|
-
- Import method: Keep React component imports
|
|
95
|
-
|
|
96
|
-
#### 3.3 Configure Exclusions
|
|
97
|
-
|
|
98
|
-
Add exclusion configurations to `vureact.config.js` to prevent manually adjusted files from being overwritten during recompilation.
|
|
99
|
-
|
|
100
|
-
If you need to modify these files later, you must **synchronize the changes manually**.
|
|
101
|
-
|
|
102
|
-
Example:
|
|
103
|
-
|
|
104
|
-
```js
|
|
105
|
-
export default defineConfig({
|
|
106
|
-
exclude: [
|
|
107
|
-
'src/main.ts',
|
|
108
|
-
'src/router/**', // Exclude the entire routing directory
|
|
109
|
-
],
|
|
110
|
-
});
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Step 4: Verification and Testing
|
|
114
|
-
|
|
115
|
-
1. Install dependencies: `npm install`
|
|
116
|
-
2. Start the project: `npm run dev`
|
|
117
|
-
3. Test route navigation
|
|
118
|
-
4. Verify nested routes
|
|
119
|
-
|
|
120
|
-
## Common Issues
|
|
121
|
-
|
|
122
|
-
### Q1: Blank Page with Console Errors
|
|
123
|
-
|
|
124
|
-
**Possible Cause**: The routing configuration file has not been converted to JSX syntax
|
|
125
|
-
**Solution**:
|
|
126
|
-
|
|
127
|
-
1. Confirm the file extension is `.tsx` or `.jsx`
|
|
128
|
-
2. Check if components use the `<Component />` syntax
|
|
129
|
-
3. Ensure React components are imported correctly
|
|
130
|
-
|
|
131
|
-
### Q2: 404 Error on Route Navigation
|
|
132
|
-
|
|
133
|
-
**Possible Cause**: Incorrect history mode configuration
|
|
134
|
-
**Solution**:
|
|
135
|
-
|
|
136
|
-
- Check `createWebHashHistory` vs `createWebHistory`
|
|
137
|
-
- Verify the base path configuration
|
|
138
|
-
|
|
139
|
-
### Q3: Nested Routes Not Displaying Content
|
|
140
|
-
|
|
141
|
-
**Possible Cause**: Parent component lacks `<RouterView />`
|
|
142
|
-
**Solution**:
|
|
143
|
-
Add a route outlet in the layout component:
|
|
144
|
-
|
|
145
|
-
```vue
|
|
146
|
-
<!-- Original Vue -->
|
|
147
|
-
<template>
|
|
148
|
-
<div>
|
|
149
|
-
<header>...</header>
|
|
150
|
-
<router-view />
|
|
151
|
-
</div>
|
|
152
|
-
</template>
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Q4: Manual Adjustments Overwritten After Compilation
|
|
156
|
-
|
|
157
|
-
**Possible Cause**: Files not added to the `exclude` list
|
|
158
|
-
**Solution**:
|
|
159
|
-
Update `vureact.config.js` and add the adjusted files to the exclusion list.
|
|
160
|
-
|
|
161
|
-
## Best Practices
|
|
162
|
-
|
|
163
|
-
### 1. Routing Configuration Specifications
|
|
164
|
-
|
|
165
|
-
- Export the router instance: `export default createRouter({})`
|
|
166
|
-
- Use named routes: `{ name: 'dashboard', path: '/dashboard', ... }`
|
|
167
|
-
- Configure route lazy loading:
|
|
168
|
-
|
|
169
|
-
```tsx
|
|
170
|
-
const Dashboard = lazy(() => import('../pages/Dashboard'));
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
- Centralize management of route meta fields
|
|
174
|
-
|
|
175
|
-
### 2. File Management Strategy
|
|
176
|
-
|
|
177
|
-
- Manage routing configuration files in a separate directory
|
|
178
|
-
- Separate type definitions into `src/router/types.ts`
|
|
179
|
-
- Unify route guards in `src/router/guards.ts`
|
|
180
|
-
|
|
181
|
-
### 3. Testing Strategy
|
|
182
|
-
|
|
183
|
-
- Unit test routing configurations
|
|
184
|
-
- E2E test route navigation flows
|
|
185
|
-
- Functional comparison testing before and after compilation
|
|
186
|
-
|
|
187
|
-
## Related Resources
|
|
188
|
-
|
|
189
|
-
- [VuReact Official Documentation](https://vureact.top/en)
|
|
190
|
-
- [VuReact Router Official Documentation](https://router.vureact.top/en)
|
|
191
|
-
- [Compilation Issue Feedback and Support](https://github.com/vureact-js/core/issues)
|
|
192
|
-
- [Routing Issue Feedback and Support](https://github.com/vureact-js/vureact-router/issues)
|