|
| 1 | +# API reference |
| 2 | + |
| 3 | +Rstack provides a unified configuration API and re-exports the public APIs of Rsbuild, Rslib, Rstest, and Rslint through dedicated subpaths. Prefer these subpaths to direct imports from each tool's core package so that dependency entry points and tool versions remain aligned with Rstack. |
| 4 | + |
| 5 | +## Import paths |
| 6 | + |
| 7 | +| Import path | Contents | Use case | |
| 8 | +| ------------------------ | ------------------------------------------------- | --------------------------------------- | |
| 9 | +| `rstack` | Rstack configuration API | Register tool configurations | |
| 10 | +| `rstack/app` | Public APIs from `@rsbuild/core` | Build applications and extend Rsbuild | |
| 11 | +| `rstack/lib` | Public APIs from `@rslib/core` | Build libraries and extend Rslib | |
| 12 | +| `rstack/test` | Public APIs from `@rstest/core` | Write tests and configure test projects | |
| 13 | +| `rstack/lint` | Public APIs from `@rslint/core` | Use Rslint presets and plugins | |
| 14 | +| `rstack/types` | Project types shared by Rsbuild and Rslib | Type application and library sources | |
| 15 | +| `rstack/test/globals` | Global Rstest API declarations | Enable global test API types | |
| 16 | +| `rstack/test/importMeta` | `ImportMeta` declaration for `import.meta.rstest` | Type in-source tests | |
| 17 | + |
| 18 | +## Main entry point |
| 19 | + |
| 20 | +### `define` |
| 21 | + |
| 22 | +Import `define` from `rstack` to register tool configurations in `rstack.config.ts`; see [Configuration APIs](./configuration#configuration-apis) for details. |
| 23 | + |
| 24 | +## Re-exports |
| 25 | + |
| 26 | +The tool-specific subpaths below re-export the public APIs from their corresponding core packages. Using these Rstack entry points keeps dependency entry points and tool versions aligned with the toolchain integrated by Rstack. |
| 27 | + |
| 28 | +### `rstack/app` |
| 29 | + |
| 30 | +`rstack/app` re-exports all public APIs from `@rsbuild/core`, including APIs for creating and controlling Rsbuild instances. |
| 31 | + |
| 32 | +```ts |
| 33 | +import { createRsbuild, mergeRsbuildConfig } from 'rstack/app'; |
| 34 | +``` |
| 35 | + |
| 36 | +For details, see the [Rsbuild core APIs](https://rsbuild.rs/api/javascript-api/core). |
| 37 | + |
| 38 | +### `rstack/lib` |
| 39 | + |
| 40 | +`rstack/lib` re-exports all public APIs from `@rslib/core`, including APIs for creating Rslib instances and merging Rslib configurations. |
| 41 | + |
| 42 | +```ts |
| 43 | +import { createRslib, mergeRslibConfig } from 'rstack/lib'; |
| 44 | +``` |
| 45 | + |
| 46 | +For details, see the [Rslib core APIs](https://rslib.rs/api/javascript-api/core). |
| 47 | + |
| 48 | +### `rstack/test` |
| 49 | + |
| 50 | +`rstack/test` re-exports all public APIs from `@rstest/core`, including APIs for defining tests, writing assertions, mocking modules, and merging test configurations. |
| 51 | + |
| 52 | +```ts |
| 53 | +import { describe, expect, test } from 'rstack/test'; |
| 54 | +``` |
| 55 | + |
| 56 | +See the [Rstest runtime API](https://rstest.rs/api/runtime-api/) for test APIs and the [Rstest core APIs](https://rstest.rs/api/javascript-api/rstest-core) for configuration helpers. |
| 57 | + |
| 58 | +### `rstack/lint` |
| 59 | + |
| 60 | +`rstack/lint` re-exports all public APIs from `@rslint/core`, including JavaScript and TypeScript presets and framework plugins. |
| 61 | + |
| 62 | +```ts |
| 63 | +import { js, reactPlugin, ts } from 'rstack/lint'; |
| 64 | +``` |
| 65 | + |
| 66 | +For details about the available presets and plugins, see [Rslint rules and presets](https://rslint.rs/config/rules-and-presets). |
| 67 | + |
| 68 | +## TypeScript types |
| 69 | + |
| 70 | +These type-only entry points add ambient declarations to a TypeScript project. Add only the entries your project needs to [`compilerOptions.types`](https://www.typescriptlang.org/tsconfig/#types) in `tsconfig.json`. |
| 71 | + |
| 72 | +### `rstack/types` |
| 73 | + |
| 74 | +`rstack/types` provides project-level declarations shared by Rsbuild and Rslib, including types for `import.meta.env` and static asset imports. Use it in place of `@rsbuild/core/types` or `@rslib/core/types`. |
| 75 | + |
| 76 | +```json title="tsconfig.json" |
| 77 | +{ |
| 78 | + "compilerOptions": { |
| 79 | + "types": ["rstack/types", "node"] |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### `rstack/test/globals` |
| 85 | + |
| 86 | +`rstack/test/globals` declares Rstest APIs such as `test`, `expect`, and lifecycle hooks as globals. Add it when tests use these APIs without explicit imports. |
| 87 | + |
| 88 | +```json title="tsconfig.json" |
| 89 | +{ |
| 90 | + "compilerOptions": { |
| 91 | + "types": ["rstack/test/globals", "node"] |
| 92 | + } |
| 93 | +} |
| 94 | +``` |
| 95 | + |
| 96 | +### `rstack/test/importMeta` |
| 97 | + |
| 98 | +`rstack/test/importMeta` augments `ImportMeta` with the optional `rstest` property, enabling `import.meta.rstest` in in-source tests. |
| 99 | + |
| 100 | +```json title="tsconfig.json" |
| 101 | +{ |
| 102 | + "compilerOptions": { |
| 103 | + "types": ["rstack/test/importMeta", "node"] |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
0 commit comments