string
undefined
Specify the library ID. The ID identifies the library and is useful when using the --lib
flag to build specific libraries with a meaningful id
in the CLI.
Rslib uses Rsbuild's environments feature to build multiple libraries in a single project under the hood. lib.id
will be used as the key for the generated Rsbuild environment.
By default, Rslib automatically generates an ID for each library in the format ${format}${index}
. Here, format
refers to the value specified in the current lib's format, and index
indicates the order of the library within all libraries of the same format. If there is only one library with the current format, the index
will be empty. Otherwise, it will start from 0
and increment.
For example, the libraries in the esm
format will start from esm0
, followed by esm1
, esm2
, and so on. In contrast, cjs
and umd
formats do not include the index
part since there is only one library for each format.
You can also specify a readable or meaningful ID of the library by setting the id
field in the library configuration. The user-specified ID will take priority, while the rest will be used together to generate the default ID.
For example, my-lib-a
, my-lib-b
, and my-lib-c
will be the IDs of the specified libraries, while the rest will be used to generate and apply the default ID.
Then you could only build my-lib-a
and my-lib-b
by running the following command:
The id of each library must be unique, otherwise it will cause an error.