Skip to content

Commit a440a3a

Browse files
committed
Merge branch 'chenjiahan/docs-shared-config' into chenjiahan/docs-shared-config-api
2 parents 437a9d4 + 7d5e23a commit a440a3a

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

‎website/docs/en/guide/configuration.mdx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,25 @@ The `doc` rules also apply to `builderConfig`: a later `builderConfig.tools.rspa
286286

287287
For `staged`, if either configuration is a top-level task-generator function, the later configuration replaces the earlier one entirely. For example, `glob mappings → function → new glob mappings` leaves only the new mappings. Task functions run when lint-staged supplies the staged file list.
288288

289-
### Dependencies and paths
289+
### Loading dependencies
290290

291291
Shared configurations can also [import dependencies dynamically](#loading-dependencies-on-demand) inside tool configuration functions, so each command loads only what it needs.
292292

293+
```ts title="shared.ts"
294+
import type { RstackConfig } from 'rstack';
295+
296+
export const sharedConfig: RstackConfig = {
297+
app: async () => {
298+
const { pluginReact } = await import('@rsbuild/plugin-react');
299+
return {
300+
plugins: [pluginReact()],
301+
};
302+
},
303+
};
304+
```
305+
306+
### Resolving paths
307+
293308
Relative paths follow each tool's existing rules; they are not automatically resolved from the shared module's directory. Use an absolute path for files shipped with the shared configuration:
294309

295310
```ts title="shared.ts"

‎website/docs/zh/guide/configuration.mdx‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,25 @@ Rstack 分别合并各个工具的配置:
286286

287287
合并 `staged` 时,只要任一配置是顶层任务生成函数,就由后一个配置整体替换前一个。例如,「glob 映射 → 函数 → 新的 glob 映射」最终只保留新的映射。任务函数由 lint-staged 传入暂存文件列表后执行。
288288

289-
### 依赖与路径 \{#dependencies-and-paths}
289+
### 依赖加载 \{#loading-dependencies}
290290

291291
公共配置也可以在工具配置函数中[动态导入依赖](#loading-dependencies-on-demand),让各命令只加载需要的依赖。
292292

293+
```ts title="shared.ts"
294+
import type { RstackConfig } from 'rstack';
295+
296+
export const sharedConfig: RstackConfig = {
297+
app: async () => {
298+
const { pluginReact } = await import('@rsbuild/plugin-react');
299+
return {
300+
plugins: [pluginReact()],
301+
};
302+
},
303+
};
304+
```
305+
306+
### 路径解析 \{#resolving-paths}
307+
293308
相对路径沿用各工具的解析规则,不会自动改为以公共模块所在目录为基准。引用公共配置自带的文件时,请使用绝对路径:
294309

295310
```ts title="shared.ts"

0 commit comments

Comments
 (0)