Skip to content

Commit f6b3281

Browse files
committed
chore: update
1 parent 588e612 commit f6b3281

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

website/docs/en/guide/solution/react.mdx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ export default defineConfig({
4545

4646
## JSX transform
4747

48-
- **Type**: `'automatic' | 'classic' | 'preserve'`
49-
- **Default**: `'automatic'`
48+
- **Type:** `'automatic' | 'classic' | 'preserve'`
49+
- **Default:** `'automatic'`
5050

5151
React introduced a [new JSX transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) in version 17. This new transform removes the need to import `React` when using JSX.
5252

53-
By default, Rsbuild uses the new JSX transform, which is `runtime: 'automatic'`. It requires at least React `16.14.0` or higher. The `peerDependencies` should be declared as `"react": ">=16.14.0"`.
53+
By default, Rslib uses the new JSX transform, which is `runtime: 'automatic'`. It requires at least React `16.14.0` or higher and the `peerDependencies` should be specified as `"react": ">=16.14.0"`.
5454

55-
To change the JSX transform, you can pass the [swcReactOptions](https://rsbuild.rs/plugins/list/plugin-react#swcreactoptionsruntime) option to the React plugin. For example, to use the classic runtime:
55+
To change the JSX transform, you can set the [swcReactOptions](https://rsbuild.rs/plugins/list/plugin-react#swcreactoptionsruntime) option in `@rsbuild/plugin-react`.
56+
57+
For example, to use the classic runtime:
5658

5759
```ts title="rslib.config.ts" twoslash
5860
import { pluginReact } from '@rsbuild/plugin-react';
@@ -76,15 +78,15 @@ export default defineConfig({
7678
});
7779
```
7880

79-
When you need to keep native JSX in the build output, set the runtime to `'preserve'`. This mode retains JSX syntax so it can be processed later (for example by another bundler).
81+
When you need to keep native JSX in the build output, you can set the runtime to `'preserve'` to leave JSX syntax unchanged without transforming it, which is useful for subsequent processing by other bundlers.
8082

81-
::: warn
83+
::: warning
8284

83-
Because the files stay unbundled, you must switch to bundleless mode by setting `bundle: false`.
85+
When using `runtime: 'preserve'`, you must set `bundle: false` to enable [bundleless mode](/guide/basic/output-structure#bundle--bundleless) to keep files unbundled.
8486

8587
:::
8688

87-
To emit `.jsx` files, configure the JS filename template through [output.filename](/config/rsbuild/output#outputfilename) while using the preserve runtime:
89+
To emit `.jsx` files, you can configure the JS filename template through [output.filename](/config/rsbuild/output#outputfilename) option:
8890

8991
```ts title="rslib.config.ts" twoslash
9092
import { pluginReact } from '@rsbuild/plugin-react';
@@ -95,9 +97,10 @@ export default defineConfig({
9597
{
9698
bundle: false,
9799
format: 'esm',
100+
// [!code highlight:5]
98101
output: {
99102
filename: {
100-
js: '[name].jsx', // [!code highlight]
103+
js: '[name].jsx',
101104
},
102105
},
103106
},

website/docs/zh/guide/solution/react.mdx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ export default defineConfig({
4545

4646
## JSX transform
4747

48-
- **类型**: `'automatic' | 'classic' | 'preserve'`
49-
- **默认值**: `'automatic'`
48+
- **类型** `'automatic' | 'classic' | 'preserve'`
49+
- **默认值** `'automatic'`
5050

5151
React 引入了一个 [新的 JSX transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) 在版本 17 中。这个新的 transform 在使用 JSX 时无需导入 `React`
5252

53-
默认情况下,Rsbuild 使用新的 JSX 转换,即 `runtime: 'automatic'`需要 React `16.14.0` 或更高版本 `peerDependencies` 中应声明 `"react": ">=16.14.0"`
53+
默认情况下,Rslib 使用新的 JSX 转换,即 `runtime: 'automatic'`这需要 React `16.14.0` 或更高版本,且 `peerDependencies` 中应声明 `"react": ">=16.14.0"`
5454

55-
要更改 JSX transform,可以传递 [swcReactOptions](https://rsbuild.rs/zh/plugins/list/plugin-react#swcreactoptionsruntime) 给 React plugin. 比如要使用 classic runtime 时:
55+
要更改 JSX transform,可以在 `@rsbuild/plugin-react` 中设置 [swcReactOptions](https://rsbuild.rs/zh/plugins/list/plugin-react#swcreactoptionsruntime) 选项。
56+
57+
比如要使用 classic runtime 时:
5658

5759
```ts title="rslib.config.ts" twoslash
5860
import { pluginReact } from '@rsbuild/plugin-react';
@@ -76,11 +78,11 @@ export default defineConfig({
7678
});
7779
```
7880

79-
当你希望在构建产物中保留原始 JSX 时,可以将 runtime 设置为 `'preserve'`该模式会保留 JSX 语法,方便后续由其他打包工具处理。
81+
当你希望在构建产物中保留原始 JSX 时,可以将 runtime 设置为 `'preserve'`该模式可以保持 JSX 语法原样,不做任何转换,方便后续由其他打包工具处理。
8082

81-
::: warn
83+
::: warning
8284

83-
因为文件保持非打包状态,所以必须通过将 `bundle` 设为 `false` 启用 bundleless 模式。
85+
使用 `runtime: 'preserve'` 时,必须设置 `bundle: false` 启用 [bundleless 模式](/guide/basic/output-structure#bundle--bundleless) 使文件保持非打包状态
8486

8587
:::
8688

@@ -95,9 +97,10 @@ export default defineConfig({
9597
{
9698
bundle: false,
9799
format: 'esm',
100+
// [!code highlight:5]
98101
output: {
99102
filename: {
100-
js: '[name].jsx', // [!code highlight]
103+
js: '[name].jsx',
101104
},
102105
},
103106
},

0 commit comments

Comments
 (0)