You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d9d6710
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: website/docs/en/guide/configuration.mdx
+118-1Lines changed: 118 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,6 +158,8 @@ When `extends` is omitted, Rstack CLI automatically connects the test configurat
158
158
159
159
If the root test configuration does not define `extends` and contains `projects`, Rstack CLI applies automatic inheritance to each inline project that omits its own `extends`. A function-based application or library configuration is resolved once and shared by those projects. String project entries are passed to Rstest unchanged; they load their external configurations independently and do not inherit the current application or library configuration.
160
160
161
+
These rules also apply to [shared configurations](#shared-configurations): Rstack first merges the test settings, then determines whether to inherit the merged App or Lib configuration.
162
+
161
163
> For more guidance on testing, see [Testing](./testing).
162
164
163
165
### `define.lint()`\{#define-lint}
@@ -201,4 +203,119 @@ define.staged({
201
203
});
202
204
```
203
205
204
-
Unlike the other commands, `rs staged` requires a `define.staged()` configuration and reports an error when it is missing.
206
+
Provide a staged configuration through `define.staged()` or a [shared configuration](#shared-configurations). `rs staged` reports an error if neither provides one.
207
+
208
+
## Shared configurations
209
+
210
+
Use `define.extends()` to share build, test, lint, and formatting settings across projects. A shared configuration is a plain object whose fields accept the same values as the corresponding `define.*()` APIs. In TypeScript, use `RstackConfig` to check its types:
The project inherits the shared settings and changes only `printWidth` to `100`.
241
+
242
+
Call `define.extends()` at most once per configuration load, with all shared configurations in a single array.
243
+
244
+
### Merge order
245
+
246
+
Configurations are applied in this order:
247
+
248
+
1. Shared configurations in the `define.extends()` array, from left to right.
249
+
2. The project's own `define.*()` configurations, even if they appear before `define.extends()` in the file.
250
+
251
+
Each tool's [merge rules](#merge-rules) determine which values are combined and which are replaced.
252
+
253
+
Shared configurations can also extend other shared configurations:
254
+
255
+
```ts title="team.ts"
256
+
importtype { RstackConfig } from'rstack';
257
+
import { sharedConfig } from'./shared.ts';
258
+
259
+
exportconst teamConfig:RstackConfig= {
260
+
extends: [sharedConfig],
261
+
test: {
262
+
retry: 3,
263
+
},
264
+
};
265
+
```
266
+
267
+
Inherited configurations are applied first. With `define.extends([teamConfig])`, the order is `sharedConfig → teamConfig → project configuration`.
268
+
269
+
Repeated references are not deduplicated. If both `a` and `b` extend `base`, `define.extends([a, b])` applies `base → a → base → b → project configuration`. Each tool handles duplicate plugins according to its own rules. Circular inheritance throws an error that identifies the circular reference.
270
+
271
+
### Merge rules
272
+
273
+
Rstack merges configurations separately for each tool:
|`lint`| Concatenates configuration arrays in order; Rslint applies their rules. |
281
+
|`fmt`| Shallow merge: later values replace earlier values for the same option. Arrays and objects, including `overrides`, are replaced as a whole. |
282
+
|`doc`| Uses Rspress's `mergeDocConfig`: recursively merges objects, appends arrays, and replaces ordinary functions with later functions. |
283
+
|`staged`| Shallow merge by glob pattern: later tasks replace earlier tasks for the same pattern, including command arrays and task functions. |
284
+
285
+
The `doc` rules also apply to `builderConfig`: a later `builderConfig.tools.rspack` callback replaces an earlier one, while callback arrays are concatenated. When an array is merged with a defined non-array value, Rspress treats that value as a single array item.
286
+
287
+
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.
288
+
289
+
### Loading dependencies
290
+
291
+
Shared configurations can also [import dependencies dynamically](#loading-dependencies-on-demand) inside tool configuration functions, so each command loads only what it needs.
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:
0 commit comments