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

# Overview

The `lib` field is an optional array of objects used to describe the library outputs generated by Rslib. Each `lib` item corresponds to one output and can contain lib configurations and [Rsbuild configurations](/config/rsbuild.md), as detailed in [Configure Rslib](/guide/basic/configure-rslib.md#configuration-structure).

- **Type:** `LibConfig[]` (see [`RslibConfig`](/api/javascript-api/types.md#rslibconfig))
- **Default:** `[{}]`
- **Required:** `false`

When the `lib` field is omitted, Rslib uses a default configuration equivalent to `lib: [{}]` to generate a single output. The output format is specified by the top-level `format`; if no top-level `format` is configured, the output format defaults to `'esm'`.

When the `lib` field is explicitly configured, its value must be a non-empty array.

For example, the following configuration will generate ESM and CJS outputs:

```js title="rslib.config.mjs"
export default {
  lib: [
    {
      format: 'esm',
    },
    {
      format: 'cjs',
    },
  ],
};
```

## Top-level lib configurations

The following lib configurations can be placed outside the `lib` field as top-level configuration shared across `lib` outputs, or inside a `lib` item to configure a specific output:

- [`autoExtension`](/config/lib/auto-extension.md)
- [`banner`](/config/lib/banner.md)
- [`bundle`](/config/lib/bundle.md)
- [`dts`](/config/lib/dts.md)
- [`externalHelpers`](/config/lib/external-helpers.md)
- [`footer`](/config/lib/footer.md)
- [`format`](/config/lib/format.md)
- [`outBase`](/config/lib/out-base.md)
- [`redirect`](/config/lib/redirect.md)
- [`shims`](/config/lib/shims.md)
- [`syntax`](/config/lib/syntax.md)
- [`wasm`](/config/lib/wasm.md)

## Non-top-level lib configurations

The following lib configurations do not support top-level configuration and can only be specified in a `lib` item to configure an individual output:

- [`experiments`](/config/lib/experiments.md)
- [`id`](/config/lib/id.md)
- [`umdName`](/config/lib/umd-name.md)
