Skip to content

Commit 17e99ae

Browse files
committed
docs: move shared configurations after configuration APIs
1 parent 2843c89 commit 17e99ae

2 files changed

Lines changed: 262 additions & 262 deletions

File tree

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

Lines changed: 131 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,137 @@ define.fmt({
7474
});
7575
```
7676

77+
## Configuration APIs
78+
79+
Configuration options follow the formats of the underlying tools. When using APIs and helpers that Rstack CLI re-exports, prefer the `rstack/app`, `rstack/lib`, `rstack/test`, and `rstack/lint` entry points.
80+
81+
| API | Tool | Commands |
82+
| ----------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
83+
| [`define.app()`](#define-app) | [Rsbuild](https://rsbuild.rs/config/) | [`rs dev`](./cli/dev), [`rs build`](./cli/build), [`rs preview`](./cli/preview) |
84+
| [`define.lib()`](#define-lib) | [Rslib](https://rslib.rs/config/) | [`rs lib`](./cli/lib) |
85+
| [`define.doc()`](#define-doc) | [Rspress](https://rspress.rs/api/config/config-basic) | [`rs doc`](./cli/doc) |
86+
| [`define.test()`](#define-test) | [Rstest](https://rstest.rs/config/) | [`rs test`](./cli/test) |
87+
| [`define.lint()`](#define-lint) | [Rslint](https://rslint.rs/config/) | [`rs lint`](./cli/lint) |
88+
| [`define.fmt()`](#define-fmt) | [Prettier](https://prettier.io/docs/options) | [`rs fmt`](./cli/fmt) |
89+
| [`define.staged()`](#define-staged) | [lint-staged](https://github.com/lint-staged/lint-staged#configuration) | [`rs staged`](./cli/staged) |
90+
91+
### `define.app()` \{#define-app}
92+
93+
Defines the [Rsbuild configuration](https://rsbuild.rs/config/) for an application. It accepts a configuration object or a configuration function. The function receives the standard Rsbuild configuration parameters.
94+
95+
```ts title="rstack.config.ts"
96+
import { define } from 'rstack';
97+
98+
define.app({
99+
html: {
100+
title: 'My App',
101+
},
102+
output: {
103+
distPath: {
104+
root: 'dist',
105+
},
106+
},
107+
});
108+
```
109+
110+
### `define.lib()` \{#define-lib}
111+
112+
Defines the [Rslib configuration](https://rslib.rs/config/) for a library. It accepts a configuration object or a configuration function. The function receives the standard Rslib configuration parameters.
113+
114+
```ts title="rstack.config.ts"
115+
import { define } from 'rstack';
116+
117+
define.lib({
118+
dts: true,
119+
format: 'esm',
120+
});
121+
```
122+
123+
### `define.doc()` \{#define-doc}
124+
125+
Defines the [Rspress configuration](https://rspress.rs/api/config/config-basic) for a documentation site. It accepts a configuration object or an async configuration function.
126+
127+
```ts title="rstack.config.ts"
128+
import { define } from 'rstack';
129+
130+
define.doc({
131+
root: 'docs',
132+
title: 'My Site',
133+
});
134+
```
135+
136+
`@rspress/core` is an optional dependency of Rstack CLI. Install it in every project that uses the `rs doc` command:
137+
138+
<PackageManagerTabs command="install -D @rspress/core" />
139+
140+
### `define.test()` \{#define-test}
141+
142+
Defines the [Rstest configuration](https://rstest.rs/config/). It accepts a configuration object or a configuration function.
143+
144+
```ts title="rstack.config.ts"
145+
import { define } from 'rstack';
146+
147+
define.app({
148+
// Shared application configuration
149+
});
150+
151+
define.test({
152+
setupFiles: ['./tests/rstest.setup.ts'],
153+
testEnvironment: 'happy-dom',
154+
});
155+
```
156+
157+
When `extends` is omitted, Rstack CLI automatically connects the test configuration to `define.app()` through the Rsbuild adapter. If no application configuration is defined, it falls back to `define.lib()` through the Rslib adapter. The application configuration takes precedence when both are defined. Set `extends` explicitly to opt out of this automatic inheritance.
158+
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+
161+
These rules also apply to shared configurations: Rstack first merges the test settings, then uses the merged App or Lib configuration for automatic inheritance.
162+
163+
> For more guidance on testing, see [Testing](./testing).
164+
165+
### `define.lint()` \{#define-lint}
166+
167+
Defines the [Rslint configuration](https://rslint.rs/config/). Pass the configuration directly, or use a synchronous or asynchronous function. The function receives all exports from `rstack/lint`, so presets and plugins do not need to be imported manually.
168+
169+
```ts title="rstack.config.ts"
170+
import { define } from 'rstack';
171+
172+
define.lint(({ js, ts }) => [
173+
js.configs.recommended,
174+
ts.configs.recommendedTypeChecked,
175+
]);
176+
```
177+
178+
### `define.fmt()` \{#define-fmt}
179+
180+
Defines formatting settings for [`rs fmt`](./cli/fmt). Pass a configuration object directly, or use a synchronous or asynchronous function that returns one.
181+
182+
```ts title="rstack.config.ts"
183+
import { define } from 'rstack';
184+
185+
define.fmt({
186+
printWidth: 100,
187+
singleQuote: true,
188+
});
189+
```
190+
191+
For detailed usage, see [Formatting](./formatting).
192+
193+
### `define.staged()` \{#define-staged}
194+
195+
Defines the [lint-staged configuration](https://github.com/lint-staged/lint-staged#configuration) used to run tasks on staged Git files. It accepts either an object that maps glob patterns to tasks or a task-generator function. Tasks can be commands, command arrays, or functions supported by lint-staged.
196+
197+
```ts title="rstack.config.ts"
198+
import { define } from 'rstack';
199+
200+
define.staged({
201+
'*.{js,jsx,ts,tsx}': ['rs lint', 'rs fmt'],
202+
'*.{json,jsonc,md,mdx,css,html,yml,yaml}': 'rs fmt',
203+
});
204+
```
205+
206+
`rs staged` requires a staged configuration, provided by `define.staged()` or a shared configuration, and reports an error when it is missing.
207+
77208
## Shared configurations
78209

79210
Use `define.extends()` to share build, test, lint, and formatting settings across projects. Define a shared configuration as a plain object with the `RstackConfig` type. Its fields accept the same values as the corresponding `define.*()` APIs:
@@ -244,134 +375,3 @@ export const sharedConfig: RstackConfig = {
244375
Publish `setup.ts` at that location in the package, or update the path to point to its compiled output.
245376

246377
Local shared modules are also tracked as configuration dependencies. Editing an imported shared module reloads the App, Lib, or Doc configuration in development or watch mode.
247-
248-
## Configuration APIs
249-
250-
Configuration options follow the formats of the underlying tools. When using APIs and helpers that Rstack CLI re-exports, prefer the `rstack/app`, `rstack/lib`, `rstack/test`, and `rstack/lint` entry points.
251-
252-
| API | Tool | Commands |
253-
| ----------------------------------- | ----------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
254-
| [`define.app()`](#define-app) | [Rsbuild](https://rsbuild.rs/config/) | [`rs dev`](./cli/dev), [`rs build`](./cli/build), [`rs preview`](./cli/preview) |
255-
| [`define.lib()`](#define-lib) | [Rslib](https://rslib.rs/config/) | [`rs lib`](./cli/lib) |
256-
| [`define.doc()`](#define-doc) | [Rspress](https://rspress.rs/api/config/config-basic) | [`rs doc`](./cli/doc) |
257-
| [`define.test()`](#define-test) | [Rstest](https://rstest.rs/config/) | [`rs test`](./cli/test) |
258-
| [`define.lint()`](#define-lint) | [Rslint](https://rslint.rs/config/) | [`rs lint`](./cli/lint) |
259-
| [`define.fmt()`](#define-fmt) | [Prettier](https://prettier.io/docs/options) | [`rs fmt`](./cli/fmt) |
260-
| [`define.staged()`](#define-staged) | [lint-staged](https://github.com/lint-staged/lint-staged#configuration) | [`rs staged`](./cli/staged) |
261-
262-
### `define.app()` \{#define-app}
263-
264-
Defines the [Rsbuild configuration](https://rsbuild.rs/config/) for an application. It accepts a configuration object or a configuration function. The function receives the standard Rsbuild configuration parameters.
265-
266-
```ts title="rstack.config.ts"
267-
import { define } from 'rstack';
268-
269-
define.app({
270-
html: {
271-
title: 'My App',
272-
},
273-
output: {
274-
distPath: {
275-
root: 'dist',
276-
},
277-
},
278-
});
279-
```
280-
281-
### `define.lib()` \{#define-lib}
282-
283-
Defines the [Rslib configuration](https://rslib.rs/config/) for a library. It accepts a configuration object or a configuration function. The function receives the standard Rslib configuration parameters.
284-
285-
```ts title="rstack.config.ts"
286-
import { define } from 'rstack';
287-
288-
define.lib({
289-
dts: true,
290-
format: 'esm',
291-
});
292-
```
293-
294-
### `define.doc()` \{#define-doc}
295-
296-
Defines the [Rspress configuration](https://rspress.rs/api/config/config-basic) for a documentation site. It accepts a configuration object or an async configuration function.
297-
298-
```ts title="rstack.config.ts"
299-
import { define } from 'rstack';
300-
301-
define.doc({
302-
root: 'docs',
303-
title: 'My Site',
304-
});
305-
```
306-
307-
`@rspress/core` is an optional dependency of Rstack CLI. Install it in every project that uses the `rs doc` command:
308-
309-
<PackageManagerTabs command="install -D @rspress/core" />
310-
311-
### `define.test()` \{#define-test}
312-
313-
Defines the [Rstest configuration](https://rstest.rs/config/). It accepts a configuration object or a configuration function.
314-
315-
```ts title="rstack.config.ts"
316-
import { define } from 'rstack';
317-
318-
define.app({
319-
// Shared application configuration
320-
});
321-
322-
define.test({
323-
setupFiles: ['./tests/rstest.setup.ts'],
324-
testEnvironment: 'happy-dom',
325-
});
326-
```
327-
328-
When `extends` is omitted, Rstack CLI automatically connects the test configuration to `define.app()` through the Rsbuild adapter. If no application configuration is defined, it falls back to `define.lib()` through the Rslib adapter. The application configuration takes precedence when both are defined. Set `extends` explicitly to opt out of this automatic inheritance.
329-
330-
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.
331-
332-
These rules also apply to shared configurations: Rstack first merges the test settings, then uses the merged App or Lib configuration for automatic inheritance.
333-
334-
> For more guidance on testing, see [Testing](./testing).
335-
336-
### `define.lint()` \{#define-lint}
337-
338-
Defines the [Rslint configuration](https://rslint.rs/config/). Pass the configuration directly, or use a synchronous or asynchronous function. The function receives all exports from `rstack/lint`, so presets and plugins do not need to be imported manually.
339-
340-
```ts title="rstack.config.ts"
341-
import { define } from 'rstack';
342-
343-
define.lint(({ js, ts }) => [
344-
js.configs.recommended,
345-
ts.configs.recommendedTypeChecked,
346-
]);
347-
```
348-
349-
### `define.fmt()` \{#define-fmt}
350-
351-
Defines formatting settings for [`rs fmt`](./cli/fmt). Pass a configuration object directly, or use a synchronous or asynchronous function that returns one.
352-
353-
```ts title="rstack.config.ts"
354-
import { define } from 'rstack';
355-
356-
define.fmt({
357-
printWidth: 100,
358-
singleQuote: true,
359-
});
360-
```
361-
362-
For detailed usage, see [Formatting](./formatting).
363-
364-
### `define.staged()` \{#define-staged}
365-
366-
Defines the [lint-staged configuration](https://github.com/lint-staged/lint-staged#configuration) used to run tasks on staged Git files. It accepts either an object that maps glob patterns to tasks or a task-generator function. Tasks can be commands, command arrays, or functions supported by lint-staged.
367-
368-
```ts title="rstack.config.ts"
369-
import { define } from 'rstack';
370-
371-
define.staged({
372-
'*.{js,jsx,ts,tsx}': ['rs lint', 'rs fmt'],
373-
'*.{json,jsonc,md,mdx,css,html,yml,yaml}': 'rs fmt',
374-
});
375-
```
376-
377-
`rs staged` requires a staged configuration, provided by `define.staged()` or a shared configuration, and reports an error when it is missing.

0 commit comments

Comments
 (0)