Skip to content

Commit 8782f6b

Browse files
authored
docs: add Chinese translation of react support (#420)
1 parent 13163fa commit 8782f6b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

docs/zh-CN/recipes/react-support.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# React 支持
2+
3+
`tsdown` 为构建 React 组件库提供了一流的支持。由于 [Rolldown](https://rolldown.rs/) 原生支持打包 JSX/TSX 文件,你无需任何额外的插件即可开始使用。
4+
5+
## 快速开始
6+
7+
最快的入门方式是使用 React 组件启动模板。这个启动项目已经为 React 库开发进行了预配置,因此你可以直接专注于构建组件。
8+
9+
```bash
10+
npx create-tsdown@latest -t react
11+
```
12+
13+
## 最小示例
14+
15+
要为 React 库配置 `tsdown`,你只需使用标准的 `tsdown.config.ts`
16+
17+
```ts [tsdown.config.ts]
18+
import { defineConfig } from 'tsdown'
19+
20+
export default defineConfig([
21+
{
22+
entry: ['./src/index.ts'],
23+
platform: 'neutral',
24+
dts: true,
25+
},
26+
])
27+
```
28+
29+
创建你的典型 React 组件:
30+
31+
```tsx [MyButton.tsx]
32+
import React from 'react'
33+
34+
interface MyButtonProps {
35+
type?: 'primary'
36+
}
37+
38+
export const MyButton: React.FC<MyButtonProps> = ({ type }) => {
39+
return <button className="my-button">my button: type {type}</button>
40+
}
41+
```
42+
43+
然后在入口文件中导入它:
44+
45+
```ts [index.ts]
46+
export { MyButton } from './MyButton'
47+
```
48+
49+
::: warning
50+
51+
`tsdown` 中有两种转换 JSX/TSX 文件的方式:
52+
53+
- **经典模式(classic)**
54+
- **自动模式(automatic)**(默认)
55+
56+
如果你需要使用经典 JSX 转换,可以在配置文件中配置 Rolldown 的 [`inputOptions.jsx`](https://rolldown.rs/reference/config-options#jsx) 选项:
57+
58+
```ts [tsdown.config.ts]
59+
import { defineConfig } from 'tsdown'
60+
61+
export default defineConfig({
62+
inputOptions: {
63+
jsx: 'react', // 使用经典 JSX 转换
64+
},
65+
})
66+
```
67+
68+
:::

0 commit comments

Comments
 (0)