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

# lib

The `rs lib` command uses [Rslib](https://rslib.rs/guide/basic/cli#rslib) to build library outputs.

## Usage

```bash
rs lib [command] [options]
```

The command loads the library configuration registered with [`define.lib()`](/guide/configuration.md#define-lib). When no subcommand is provided, it builds the library.

## Options

`rs lib` supports the same library build options as Rslib. See the [Rslib CLI documentation](https://rslib.rs/guide/basic/cli#rslib) for details.

Examples:

```bash
# Build and generate declaration files
rs lib --dts

# Rebuild when files change
rs lib --watch
```

## Subcommands

### build

[`rs lib build`](https://rslib.rs/guide/basic/cli#rslib) builds library outputs for production. It is equivalent to running `rs lib` without a subcommand.

```bash
rs lib build
```

### inspect

[`rs lib inspect`](https://rslib.rs/guide/basic/cli#rslib-inspect) generates the normalized Rslib configuration and the corresponding Rsbuild and Rspack configurations for inspection.

```bash
rs lib inspect
```

### mf-dev

[`rs lib mf-dev`](https://rslib.rs/guide/basic/cli#rslib-mf-dev) starts an Rsbuild development server for a library output that uses the Module Federation (`mf`) format. Use it to develop and debug the module in a host application.

```bash
rs lib mf-dev
```

## Configuration

Configure library builds through [`define.lib()`](/guide/configuration.md#define-lib) in the [Rstack configuration file](/guide/configuration.md#configuration-file). It accepts the standard [Rslib configuration](https://rslib.rs/config/):

```ts title="rstack.config.ts"
import { define } from 'rstack';

define.lib({
  dts: true,
  format: 'esm',
});
```
