Skip to content

Commit 1c88e0f

Browse files
authored
docs: clarify config import guidance (#449)
1 parent 1fd1fbc commit 1c88e0f

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

website/docs/en/guide/configuration.mdx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ All `rs` commands accept the global `-c, --config` option for loading a file wit
4444
rs build --config ./configs/rstack.config.ts
4545
```
4646

47-
## Loading dependencies on demand
47+
## Importing dependencies \{#loading-dependencies-on-demand}
4848

49-
Every `rs` command loads and executes the Rstack configuration file, then resolves only the configuration functions needed by that command.
49+
Rstack keeps a project's build, test, lint, formatting, and other settings in one `rstack.config.*` file. When a command loads the config file, it also loads every top-level import, even if it does not use the related configuration. Importing every tool and plugin at the top level can therefore add startup overhead to commands such as `rs lint` and `rs fmt`.
5050

51-
When a configuration needs to import plugins or other tool-specific dependencies, use an async configuration function and load those dependencies with dynamic `import()` inside it. This ensures that they are loaded only when the configuration is resolved.
51+
Choose the import style based on the config contents:
52+
53+
- Prefer simpler static imports when the config is only for an application and its tests, a library and its tests, or a documentation site.
54+
- If the same config also includes lint, formatting, or staged-file checks, consider dynamically importing dependencies inside the relevant async configuration function. This lets checks skip those dependencies.
5255

5356
```ts title="rstack.config.ts"
5457
import { define } from 'rstack';
@@ -59,6 +62,12 @@ define.app(async () => {
5962
plugins: [pluginReact()],
6063
};
6164
});
65+
66+
define.lint(({ js }) => [js.configs.recommended]);
67+
68+
define.fmt({
69+
singleQuote: true,
70+
});
6271
```
6372

6473
## Configuration APIs

website/docs/en/guide/monorepo.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,11 @@ Rstack CLI loads the configuration from the current working directory. It does n
117117
A web application usually needs application build configuration and optional test configuration:
118118

119119
```ts title="apps/web/rstack.config.ts"
120+
import { pluginReact } from '@rsbuild/plugin-react';
120121
import { define } from 'rstack';
121122

122-
define.app(async () => {
123-
const { pluginReact } = await import('@rsbuild/plugin-react');
124-
return {
125-
plugins: [pluginReact()],
126-
};
123+
define.app({
124+
plugins: [pluginReact()],
127125
});
128126

129127
define.test({

website/docs/zh/guide/configuration.mdx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ Rstack CLI 默认会查找使用以下任一文件名的配置文件:
4444
rs build --config ./configs/rstack.config.ts
4545
```
4646

47-
## 按需加载依赖 \{#loading-dependencies-on-demand}
47+
## 导入依赖 \{#loading-dependencies-on-demand}
4848

49-
每次执行 `rs` 命令时,Rstack CLI 都会加载并执行配置文件,然后只解析当前命令需要的配置函数
49+
Rstack 将项目的构建、测试、代码检查、格式化等配置集中在一个 `rstack.config.*` 文件中。命令加载配置文件时,会同时加载所有顶层 `import`,即使当前命令用不到对应的配置。因此,在顶层导入所有工具和插件可能会增加 `rs lint``rs fmt` 等命令的启动开销
5050

51-
如果配置需要导入插件或其他工具专属依赖,请使用异步配置函数,并在函数内通过动态 `import()` 加载这些依赖。这样只有解析该配置时才会加载相关依赖。
51+
请根据配置内容选择导入方式:
52+
53+
- 如果配置只用于一个应用及其测试、一个库及其测试或一个文档站点,优先使用更简洁的静态导入。
54+
- 如果同一配置还包含 lint、格式化或暂存文件检查,可在相应的异步配置函数中动态导入依赖,让检查命令跳过这些依赖。
5255

5356
```ts title="rstack.config.ts"
5457
import { define } from 'rstack';
@@ -59,6 +62,12 @@ define.app(async () => {
5962
plugins: [pluginReact()],
6063
};
6164
});
65+
66+
define.lint(({ js }) => [js.configs.recommended]);
67+
68+
define.fmt({
69+
singleQuote: true,
70+
});
6271
```
6372

6473
## 配置 API \{#configuration-apis}

website/docs/zh/guide/monorepo.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,11 @@ Rstack CLI 会加载当前工作目录中的配置,不会将子项目配置与
117117
Web 应用通常需要应用构建配置和可选的测试配置:
118118

119119
```ts title="apps/web/rstack.config.ts"
120+
import { pluginReact } from '@rsbuild/plugin-react';
120121
import { define } from 'rstack';
121122

122-
define.app(async () => {
123-
const { pluginReact } = await import('@rsbuild/plugin-react');
124-
return {
125-
plugins: [pluginReact()],
126-
};
123+
define.app({
124+
plugins: [pluginReact()],
127125
});
128126

129127
define.test({

0 commit comments

Comments
 (0)