close
  • English
  • 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, as detailed in Configure Rslib.

    • Type: LibConfig[] (see 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:

    rslib.config.mjs
    export default {
      lib: [
        {
          format: 'esm',
        },
        {
          format: 'cjs',
        },
      ],
    };

    Shared lib configurations

    The following lib configurations can be placed outside the lib field as shared configuration for all outputs or inside a lib item to configure a specific output:

    Non-shared lib configurations

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