CLI
Rslib comes with a lightweight CLI that includes commands such as rslib and rslib inspect.
All commands
To view all available CLI commands, run the following command in the project directory:
The output is shown below:
Common flags
Rslib CLI provides several common flags that can be used with all commands:
rslib
The rslib command will build the outputs for production in the dist/ directory by default. rslib build is an alias for the rslib command.
If the Rslib configuration file is not present in your project, the CLI will automatically use the default configuration containing only a single lib and apply all build options from the command line. You can add a configuration file once you need a more complex configuration or want to build outputs in multiple formats.
Environment variables
Rslib supports injecting environment variables or expressions into the code during the build, which is helpful for distinguishing running environments or replacing constants. You can see more details in Rsbuild - Environment variables.
By default, Rslib sets the process.env.NODE_ENV environment variable, which is always 'production' during the build. If you need to distinguish watch mode to dynamically set different configurations, you can set as follows:
rslib inspect
The rslib inspect command inspects a project's Rslib config and the corresponding Rsbuild and Rspack configs.
When you run the command npx rslib inspect in the project root directory, the following files will be generated in the dist/.rsbuild directory of the project:
rsbuild.config.mjs: Represents the Rsbuild configuration used during the build.rspack.config.esm.mjs: Represents the Rspack configuration used during the build.rslib.config.mjs: Represents the resolved Rslib configuration.
Setting mode
By default, mode is inferred from process.env.NODE_ENV: it is 'development' when NODE_ENV is 'development', and 'production' otherwise.
When mode is 'production', the inspect command outputs production mode configurations for all libraries. You can add the --mode development option to output development mode configurations for libraries with format set to mf:
Verbose content
By default, the inspect command omits function bodies in the configuration object. To output complete function content, add the --verbose option:
Multiple output formats
If the current project has multiple output formats, such as ESM artifact and CJS artifact simultaneously, multiple Rspack configuration files will be generated in the dist/.rsbuild directory.
rslib mf-dev
The rslib mf-dev command is utilized to start Rsbuild dev server for the Module Federation format.
This enables you to develop and debug your mf format module within the host app.
