> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# API reference

Rstack CLI 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 stay unified and APIs match the tool versions integrated by Rstack CLI.

## Import paths

| Import path              | Contents                                          | Use case                                |
| ------------------------ | ------------------------------------------------- | --------------------------------------- |
| `rstack`                 | Rstack CLI configuration API                      | Register tool configurations            |
| `rstack/config`          | Configuration loader and its types                | Load shared and project configurations  |
| `rstack/app`             | Public APIs from `@rsbuild/core`                  | Build applications and extend Rsbuild   |
| `rstack/lib`             | Public APIs from `@rslib/core`                    | Build libraries and extend Rslib        |
| `rstack/test`            | Public APIs from `@rstest/core`                   | Write tests and configure test projects |
| `rstack/lint`            | Public APIs from `@rslint/core`                   | Use Rslint presets and plugins          |
| `rstack/types`           | Project types shared by Rsbuild and Rslib         | Type application and library sources    |
| `rstack/test/globals`    | Global Rstest API declarations                    | Enable global test API types            |
| `rstack/test/importMeta` | `ImportMeta` declaration for `import.meta.rstest` | Type in-source tests                    |

## Main entry point

### `define`

Import `define` from `rstack` to register tool configurations in `rstack.config.ts`; see [Configuration APIs](/guide/configuration.md#configuration-apis) for details.

### `RstackConfig`

`RstackConfig` is the type for a [shared configuration](/guide/configuration.md#shared-configurations). All fields are optional, so include only the settings you want to share.

Each tool field accepts the same configuration as its corresponding `define.*()` method. For example, `fmt` accepts the same input as `define.fmt()`.

```ts title="shared.ts"
import type { RstackConfig } from 'rstack';

export const sharedConfig: RstackConfig = {
  fmt: {
    singleQuote: true,
  },
};
```

Use the `extends` field to inherit other shared configurations. Its type is `readonly RstackConfig[]`.

```ts title="team.ts"
import type { RstackConfig } from 'rstack';
import { sharedConfig } from './shared.ts';

export const teamConfig: RstackConfig = {
  extends: [sharedConfig],
  fmt: {
    printWidth: 100,
  },
};
```

## Re-exports

The tool-specific subpaths below re-export the public APIs from their corresponding core packages. Using these entry points keeps imports unified and APIs aligned with the tool versions integrated by Rstack CLI.

### `rstack/app`

`rstack/app` re-exports all public APIs from `@rsbuild/core`, including APIs for creating and controlling Rsbuild instances.

```ts
import { createRsbuild, mergeRsbuildConfig } from 'rstack/app';
```

For details, see the [Rsbuild core APIs](https://rsbuild.rs/api/javascript-api/core).

### `rstack/lib`

`rstack/lib` re-exports all public APIs from `@rslib/core`, including APIs for creating Rslib instances and merging Rslib configurations.

```ts
import { createRslib, mergeRslibConfig } from 'rstack/lib';
```

For details, see the [Rslib core APIs](https://rslib.rs/api/javascript-api/core).

### `rstack/test`

`rstack/test` re-exports all public APIs from `@rstest/core`, including APIs for defining tests, writing assertions, mocking modules, and merging test configurations.

```ts
import { describe, expect, test } from 'rstack/test';
```

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.

> For more guidance on testing, see [Testing](/guide/testing.md).

### `rstack/lint`

`rstack/lint` re-exports all public APIs from `@rslint/core`, including JavaScript and TypeScript presets and framework plugins.

```ts
import { js, reactPlugin, ts } from 'rstack/lint';
```

For details about the available presets and plugins, see [Rslint rules and presets](https://rslint.rs/config/rules-and-presets).

## Loading configurations

### `loadRstackConfig()` \{#loadrstackconfig}

Use `loadRstackConfig()` from `rstack/config` to load Rstack configurations in your own code:

```ts
import { loadRstackConfig } from 'rstack/config';

const { configs, filePath, dependencies } = await loadRstackConfig({
  cwd: process.cwd(),
  configFilePath: './rstack.config.ts',
});
```

The function accepts these optional parameters:

- `cwd`: the directory to search for a configuration file. Relative `configFilePath` values are also resolved from this directory. Defaults to the current working directory.
- `configFilePath`: a relative or absolute path to the configuration file. If omitted, the loader uses the path specified by the CLI's `--config` option. If neither is set, it searches `cwd` for the [default file names](/guide/configuration.md#configuration-file).

The returned object has these fields:

- `configs`: configuration objects or functions for each tool, including project settings and inherited [shared configurations](/guide/configuration.md#shared-configurations).
- `filePath`: the loaded configuration file's path, or `null` if no file was found.
- `dependencies`: paths to configuration dependencies collected by the loader.

`loadRstackConfig()` only loads configurations; it does not run tool configuration functions. Before running a tool, the caller must resolve its configuration and initialize it.

`rstack/config` also exports the related types: `LoadRstackConfigOptions` for the parameters, `LoadedRstackConfig` for the return value, and `RstackConfigDefinitions` for the tool configurations.

## TypeScript types

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`.

### `rstack/types`

`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`.

```json title="tsconfig.json"
{
  "compilerOptions": {
    "types": ["rstack/types", "node"]
  }
}
```

### `rstack/test/globals`

`rstack/test/globals` declares Rstest APIs such as `test`, `expect`, and lifecycle hooks as globals. Add it when Rstest's [`globals`](https://rstest.rs/config/test/globals) option is enabled and tests use these APIs without explicit imports.

```json title="tsconfig.json"
{
  "compilerOptions": {
    "types": ["rstack/test/globals", "node"]
  }
}
```

### `rstack/test/importMeta`

`rstack/test/importMeta` augments `ImportMeta` with the optional `rstest` property, providing type support for `import.meta.rstest` in in-source tests.

```json title="tsconfig.json"
{
  "compilerOptions": {
    "types": ["rstack/test/importMeta", "node"]
  }
}
```
