Skip to content

Commit e3b7ff5

Browse files
authored
docs(cn): translate target.md into Chinese (#1782)
2 parents 2a3eede + 58bd907 commit e3b7ff5

File tree

1 file changed

+43
-43
lines changed
  • src/content/reference/react-compiler

1 file changed

+43
-43
lines changed

src/content/reference/react-compiler/target.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: target
44

55
<Intro>
66

7-
The `target` option specifies which React version the compiler should generate code for.
7+
`target` 选项用于指定编译器应为哪个 React 版本生成代码。
88

99
</Intro>
1010

@@ -18,67 +18,67 @@ The `target` option specifies which React version the compiler should generate c
1818

1919
---
2020

21-
## Reference {/*reference*/}
21+
## 参考 {/*reference*/}
2222

2323
### `target` {/*target*/}
2424

25-
Configures the React version compatibility for the compiled output.
25+
为编译输出配置目标 React 版本的兼容性。
2626

27-
#### Type {/*type*/}
27+
#### 类型 {/*type*/}
2828

2929
```
3030
'17' | '18' | '19'
3131
```
3232

33-
#### Default value {/*default-value*/}
33+
#### 默认值 {/*default-value*/}
3434

3535
`'19'`
3636

37-
#### Valid values {/*valid-values*/}
37+
#### 有效值 {/*valid-values*/}
3838

39-
- **`'19'`**: Target React 19 (default). No additional runtime required.
40-
- **`'18'`**: Target React 18. Requires `react-compiler-runtime` package.
41-
- **`'17'`**: Target React 17. Requires `react-compiler-runtime` package.
39+
- **`'19'`**: React 19 为目标(默认)。无需额外运行时。
40+
- **`'18'`**: React 18 为目标。需要安装 `react-compiler-runtime` 包。
41+
- **`'17'`**: React 17 为目标。需要安装 `react-compiler-runtime` 包。
4242

43-
#### Caveats {/*caveats*/}
44-
45-
- Always use string values, not numbers (e.g., `'17'` not `17`)
46-
- Don't include patch versions (e.g., use `'18'` not `'18.2.0'`)
47-
- React 19 includes built-in compiler runtime APIs
48-
- React 17 and 18 require installing `react-compiler-runtime@rc`
43+
#### 注意事项 {/*caveats*/}
4944

45+
- 始终使用字符串值,不要用数字(例如使用 `'17'` 而非 `17`
46+
- 不要包含补丁版本号(例如使用 `'18'` 而非 `'18.2.0'`
47+
- React 19 已内置编译器运行时 API
48+
- React 17 与 18 需要安装 `react-compiler-runtime@rc`
49+
5050
---
5151

52-
## Usage {/*usage*/}
52+
## 用法 {/*usage*/}
5353

54-
### Targeting React 19 (default) {/*targeting-react-19*/}
54+
### React 19 为目标(默认) {/*targeting-react-19*/}
5555

56-
For React 19, no special configuration is needed:
56+
对于 React 19,无需额外配置:
5757

5858
```js
5959
{
6060
// defaults to target: '19'
6161
}
6262
```
6363

64-
The compiler will use React 19's built-in runtime APIs:
64+
编译器会使用 React 19 的内置运行时 API:
6565

6666
```js
67-
// Compiled output uses React 19's native APIs
67+
// 编译输出使用 React 19 的原生 API
6868
import { c as _c } from 'react/compiler-runtime';
6969
```
7070

71-
### Targeting React 17 or 18 {/*targeting-react-17-or-18*/}
71+
### React 17 18 为目标 {/*targeting-react-17-or-18*/}
7272

73-
For React 17 and React 18 projects, you need two steps:
73+
对于 React 17 React 18 项目,需要两步:
7474

75-
1. Install the runtime package:
75+
1. 安装运行环境包:
7676

7777
```bash
7878
npm install react-compiler-runtime@rc
7979
```
8080

81-
2. Configure the target:
81+
2. 配置 target:
8282

8383
```js
8484
// For React 18
@@ -92,7 +92,7 @@ npm install react-compiler-runtime@rc
9292
}
9393
```
9494

95-
The compiler will use the polyfill runtime for both versions:
95+
编译器会在这两个版本上使用 polyfill 运行环境:
9696

9797
```js
9898
// Compiled output uses the polyfill
@@ -101,48 +101,48 @@ import { c as _c } from 'react-compiler-runtime';
101101

102102
---
103103

104-
## Troubleshooting {/*troubleshooting*/}
104+
## 故障排除 {/*troubleshooting*/}
105105

106-
### Runtime errors about missing compiler runtime {/*missing-runtime*/}
106+
### 关于缺少编译器运行环境导致的运行环境错误 {/*missing-runtime*/}
107107

108-
If you see errors like "Cannot find module 'react/compiler-runtime'":
108+
如果你看到类似 “Cannot find module 'react/compiler-runtime'” 的错误:
109109

110-
1. Check your React version:
110+
1. 检查你的 React 版本:
111111
```bash
112112
npm why react
113113
```
114114

115-
2. If using React 17 or 18, install the runtime:
115+
2. 如果使用 React 17 18,安装运行环境:
116116
```bash
117117
npm install react-compiler-runtime@rc
118118
```
119119

120-
3. Ensure your target matches your React version:
120+
3. 确保你的 target 和你的 React 版本一致:
121121
```js
122122
{
123-
target: '18' // Must match your React major version
123+
target: '18' // 必须与你的 React 主要版本一致
124124
}
125125
```
126126

127-
### Runtime package not working {/*runtime-not-working*/}
127+
### 运行环境包不起作用 {/*runtime-not-working*/}
128128

129-
Ensure the runtime package is:
129+
请确保运行环境包:
130130

131-
1. Installed in your project (not globally)
132-
2. Listed in your `package.json` dependencies
133-
3. The correct version (`@rc` tag)
134-
4. Not in `devDependencies` (it's needed at runtime)
131+
1. 安装在你的项目中(而非全局)
132+
2. 被列在 `package.json` dependencies
133+
3. 使用正确版本(`@rc` 标签)
134+
4. 不在 `devDependencies` 中(运行环境需要)
135135

136-
### Checking compiled output {/*checking-output*/}
136+
### 检查编译输出 {/*checking-output*/}
137137

138-
To verify the correct runtime is being used, note the different import (`react/compiler-runtime` for builtin, `react-compiler-runtime` standalone package for 17/18):
138+
要验证使用的是正确的运行环境,注意导入路径的区别(React 19 使用内置的 `react/compiler-runtime`,React 17/18 使用独立包 `react-compiler-runtime`):
139139

140140
```js
141-
// For React 19 (built-in runtime)
141+
// 对于 React 19(内置运行环境)
142142
import { c } from 'react/compiler-runtime'
143143
// ^
144144

145-
// For React 17/18 (polyfill runtime)
145+
// 对于 React 17/18polyfill 运行环境)
146146
import { c } from 'react-compiler-runtime'
147147
// ^
148-
```
148+
```

0 commit comments

Comments
 (0)