Default behavior
Rslib builds on Rsbuild and Rspack, adapting some of their default behaviors for library builds.
These default behaviors typically depend on options such as format, bundle, and output.target, as well as specific fields in the package.json and tsconfig.json files. You can change these behaviors through configuration and plugins.
Environment variables
When building library code, Rslib uses format to determine whether to preserve process.env.NODE_ENV expressions from the source code in the output or replace them with a specified value at build time:
You can specify a replacement value with source.define, or configure Rspack's optimization.nodeEnv through tools.rspack to adjust or disable replacement.
For details on other predefined environment variables, .env file loading rules, and variable replacement, see Environment variables.
Format, entries, and dependencies
The defaults for each format are:
Automatic externalization of JavaScript dependencies through output.autoExternal only applies in bundle mode.
format and output.target specify the module format and target runtime, respectively. For browser libraries, set output.target to 'web', and MF also requires the Module Federation plugin.
Based on the output format, target runtime, and bundle setting, Rslib applies the following defaults to entries, directory structure, and dependencies:
Syntax and module compatibility
Optimization and chunks
Rslib uses Rsbuild's mode configuration to select build and optimization behavior:
rslibandrslib --watchuse'production', with watch mode only adding file watching and rebuilds.rslib mf-devuses'development'for the MF development server.
mode is configured independently of the build process's NODE_ENV. For example, NODE_ENV=development rslib still builds with mode: 'production'.
Rslib adjusts the following optimization defaults:
- Setting
output.minifyreplaces Rslib's entire minimizer preset, even when you pass a partial object.output.minify: falsedisables only the minimizer. Rspack still analyzes used exports and side effects, but unused declarations may remain in the output. splitChunks.preset: 'none'does not guarantee a single output file: dynamic imports, multiple entries, Workers, and runtime code can produce additional files.
Output files
Static assets
CSS
Type declarations
Rslib does not generate type declarations by default. dts: true emits unbundled declarations independently of JavaScript's bundle setting. Multiple JavaScript outputs can share declarations, so enabling dts in one lib item is usually enough.
Build performance and output size
Change and inspect defaults
Put shared settings at the top level and settings for one output in its lib item. Per-lib settings take priority over shared settings and determine the corresponding default behavior. Explicit CLI build options override the corresponding file configuration; see CLI.
Objects are usually merged recursively and arrays appended, while options such as resolve.extensions are replaced. See Configuration merge rules. When combining configurations with mergeRslibConfig, lib items with the same id are merged and items without an id are appended.
You can adjust the Rspack options in the tables through tools.rspack and check its documentation for usage, while other Rslib and Rsbuild options are listed in the Configuration overview.
You can enable debug mode or run rslib inspect to view the final generated configuration.
