Skip to content

Commit 8b9c6ba

Browse files
Sunny-117claude
andcommitted
docs: standardize documentation style with anchor IDs and VitePress containers
- Add anchor IDs to all headings (e.g., `## Title {#anchor}`) - Replace `> [!TIP]` syntax with VitePress containers (`:::tip`) - Use `sh` instead of `bash` for shell code blocks - Add file name labels to code blocks (e.g., ` ```ts [build.config.ts] `) - Add complete import statements in code examples - Add "Next Steps" section at the end of each document - Remove unused VitePress example file (api-examples.md) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9018a88 commit 8b9c6ba

27 files changed

+980
-621
lines changed

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"Bash(../../node_modules/.bin/esno:*)",
4242
"Bash(git restore:*)",
4343
"Bash(pnpm test:coverage:*)",
44-
"Bash(pnpm docs:build:*)"
44+
"Bash(pnpm docs:build:*)",
45+
"Bash(git checkout:*)"
4546
]
4647
}
4748
}

docs/advanced/hooks.md

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Hooks 钩子
1+
# Hooks 钩子 {#hooks}
22

33
`robuild` 提供构建生命周期钩子,允许在构建过程的不同阶段执行自定义逻辑。
44

5-
## 可用钩子
5+
## 可用钩子 {#available-hooks}
66

77
```ts [build.config.ts]
88
import { defineConfig } from 'robuild'
@@ -34,49 +34,49 @@ export default defineConfig({
3434
})
3535
```
3636

37-
## 钩子说明
37+
## 钩子说明 {#hook-descriptions}
3838

39-
### `start`
39+
### `start` {#start}
4040

4141
构建开始时触发。
4242

4343
```ts
4444
start?: (ctx: BuildContext) => void | Promise<void>
4545
```
4646

47-
### `entries`
47+
### `entries` {#entries}
4848

4949
入口解析完成后触发,可以修改入口配置。
5050

5151
```ts
5252
entries?: (entries: BuildEntry[], ctx: BuildContext) => void | Promise<void>
5353
```
5454

55-
### `rolldownConfig`
55+
### `rolldownConfig` {#rolldown-config}
5656

5757
Rolldown 配置生成后触发,可以修改配置。
5858

5959
```ts
6060
rolldownConfig?: (config: InputOptions, ctx: BuildContext) => void | Promise<void>
6161
```
6262

63-
### `rolldownOutput`
63+
### `rolldownOutput` {#rolldown-output}
6464

6565
输出配置生成后触发。
6666

6767
```ts
6868
rolldownOutput?: (config: OutputOptions, result: RolldownBuild, ctx: BuildContext) => void | Promise<void>
6969
```
7070

71-
### `end`
71+
### `end` {#end}
7272

7373
构建完成后触发。
7474

7575
```ts
7676
end?: (ctx: BuildContext) => void | Promise<void>
7777
```
7878

79-
## BuildContext
79+
## BuildContext {#build-context}
8080

8181
钩子函数接收的上下文对象:
8282

@@ -87,14 +87,22 @@ interface BuildContext {
8787
}
8888
```
8989

90-
## 使用示例
90+
## 使用示例 {#examples}
9191

92-
### 构建耗时统计
92+
### 构建耗时统计 {#build-timing}
9393

9494
```ts [build.config.ts]
95+
import { defineConfig } from 'robuild'
96+
9597
let startTime: number
9698

9799
export default defineConfig({
100+
entries: [
101+
{
102+
type: 'bundle',
103+
input: './src/index.ts',
104+
},
105+
],
98106
hooks: {
99107
start: () => {
100108
startTime = Date.now()
@@ -106,10 +114,18 @@ export default defineConfig({
106114
})
107115
```
108116

109-
### 修改 Rolldown 配置
117+
### 修改 Rolldown 配置 {#modify-rolldown-config}
110118

111119
```ts [build.config.ts]
120+
import { defineConfig } from 'robuild'
121+
112122
export default defineConfig({
123+
entries: [
124+
{
125+
type: 'bundle',
126+
input: './src/index.ts',
127+
},
128+
],
113129
hooks: {
114130
rolldownConfig: (config) => {
115131
config.treeshake = false
@@ -118,5 +134,11 @@ export default defineConfig({
118134
})
119135
```
120136

121-
> [!TIP]
122-
> 钩子适用于简单的构建过程扩展。对于复杂的代码转换需求,推荐使用插件。
137+
:::tip
138+
钩子适用于简单的构建过程扩展。对于复杂的代码转换需求,推荐使用插件。
139+
:::
140+
141+
## 下一步 {#next-steps}
142+
143+
- [插件](./plugins.md) - 插件系统
144+
- [程序化使用](./programmatic-usage.md) - API 调用

docs/advanced/plugins.md

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# 插件
1+
# 插件 {#plugins}
22

33
`robuild`[Rolldown](https://rolldown.rs) 作为核心引擎,支持丰富的插件生态。
44

5-
## 支持的插件生态
5+
## 支持的插件生态 {#supported-ecosystems}
66

7-
### Rolldown 插件
7+
### Rolldown 插件 {#rolldown-plugins}
88

99
由于 `robuild` 基于 Rolldown 构建,因此支持所有 Rolldown 插件:
1010

@@ -23,7 +23,7 @@ export default defineConfig({
2323
})
2424
```
2525

26-
### Unplugin
26+
### Unplugin {#unplugin}
2727

2828
[Unplugin](https://unplugin.unjs.io/) 是一个现代化的插件框架,支持多种打包器。大多数 Unplugin 插件都可以与 `robuild` 配合使用:
2929

@@ -42,7 +42,7 @@ export default defineConfig({
4242
})
4343
```
4444

45-
### Rollup 插件
45+
### Rollup 插件 {#rollup-plugins}
4646

4747
Rolldown 与 Rollup 的插件 API 高度兼容,大多数 Rollup 插件可以直接使用:
4848

@@ -61,15 +61,27 @@ export default defineConfig({
6161
})
6262
```
6363

64-
> [!NOTE]
65-
> 由于 Rollup 和 Rolldown 的 API 并非 100% 兼容,某些插件可能有类型错误。可以使用 `as any` 忽略:
66-
> ```ts
67-
> plugins: [SomeRollupPlugin() as any]
68-
> ```
64+
:::warning
65+
由于 Rollup 和 Rolldown 的 API 并非 100% 兼容,某些插件可能有类型错误。可以使用 `as any` 忽略:
6966

70-
## 全局插件 vs 入口插件
67+
```ts [build.config.ts]
68+
import { defineConfig } from 'robuild'
7169

72-
### 全局插件
70+
export default defineConfig({
71+
entries: [
72+
{
73+
type: 'bundle',
74+
input: './src/index.ts',
75+
plugins: [SomeRollupPlugin() as any],
76+
},
77+
],
78+
})
79+
```
80+
:::
81+
82+
## 全局插件 vs 入口插件 {#global-vs-entry-plugins}
83+
84+
### 全局插件 {#global-plugins}
7385

7486
在顶层配置,对所有入口生效:
7587

@@ -85,7 +97,7 @@ export default defineConfig({
8597
})
8698
```
8799

88-
### 入口插件
100+
### 入口插件 {#entry-plugins}
89101

90102
在入口配置,只对该入口生效:
91103

@@ -103,11 +115,13 @@ export default defineConfig({
103115
})
104116
```
105117

106-
## 编写自定义插件
118+
## 编写自定义插件 {#custom-plugins}
107119

108120
可以使用 Rolldown 的插件 API 编写自定义插件:
109121

110122
```ts [build.config.ts]
123+
import { defineConfig } from 'robuild'
124+
111125
const myPlugin = () => ({
112126
name: 'my-plugin',
113127
transform(code, id) {
@@ -129,3 +143,8 @@ export default defineConfig({
129143
```
130144

131145
详细信息请参阅 [Rolldown 插件开发指南](https://rolldown.rs/guide/plugin-development)
146+
147+
## 下一步 {#next-steps}
148+
149+
- [Hooks 钩子](./hooks.md) - 构建生命周期钩子
150+
- [Rolldown 选项](./rolldown-options.md) - 直接传递 Rolldown 配置

docs/advanced/programmatic-usage.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# 程序化使用
1+
# 程序化使用 {#programmatic-usage}
22

33
除了 CLI,`robuild` 还提供程序化 API,可以在 Node.js 脚本中调用。
44

5-
## 基本用法
5+
## 基本用法 {#basic-usage}
66

77
```ts [scripts/build.ts]
88
import { build } from 'robuild'
@@ -19,13 +19,13 @@ await build({
1919
})
2020
```
2121

22-
## API
22+
## API {#api}
2323

24-
### `build(config)`
24+
### `build(config)` {#build}
2525

2626
执行构建:
2727

28-
```ts
28+
```ts [scripts/build.ts]
2929
import { build } from 'robuild'
3030

3131
await build({
@@ -43,11 +43,11 @@ await build({
4343
})
4444
```
4545

46-
### `defineConfig(config)`
46+
### `defineConfig(config)` {#define-config}
4747

4848
配置辅助函数,提供类型提示:
4949

50-
```ts
50+
```ts [build.config.ts]
5151
import { defineConfig } from 'robuild'
5252

5353
const config = defineConfig({
@@ -60,9 +60,9 @@ const config = defineConfig({
6060
})
6161
```
6262

63-
## 完整示例
63+
## 完整示例 {#examples}
6464

65-
### 条件构建
65+
### 条件构建 {#conditional-build}
6666

6767
```ts [scripts/build.ts]
6868
import { build } from 'robuild'
@@ -83,7 +83,7 @@ await build({
8383
})
8484
```
8585

86-
### 多包构建
86+
### 多包构建 {#multi-package-build}
8787

8888
```ts [scripts/build.ts]
8989
import { build } from 'robuild'
@@ -105,7 +105,7 @@ for (const pkg of packages) {
105105
}
106106
```
107107

108-
### 与其他工具集成
108+
### 与其他工具集成 {#integration}
109109

110110
```ts [scripts/build.ts]
111111
import { build } from 'robuild'
@@ -125,7 +125,7 @@ await build({
125125
execSync('pnpm test', { stdio: 'inherit' })
126126
```
127127

128-
## 类型导出
128+
## 类型导出 {#type-exports}
129129

130130
```ts
131131
import type {
@@ -138,5 +138,11 @@ import type {
138138
} from 'robuild'
139139
```
140140

141-
> [!TIP]
142-
> 程序化 API 适合复杂的构建场景,如 monorepo 批量构建、条件构建、与 CI/CD 集成等。
141+
:::tip
142+
程序化 API 适合复杂的构建场景,如 monorepo 批量构建、条件构建、与 CI/CD 集成等。
143+
:::
144+
145+
## 下一步 {#next-steps}
146+
147+
- [Hooks 钩子](./hooks.md) - 构建生命周期钩子
148+
- [CLI 参考](../reference/cli.md) - 命令行参考

0 commit comments

Comments
 (0)