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.
Watch mode
Use rslib --watch or rslib -w to enable watch mode. Rslib watches for source file changes and automatically rebuilds when they change.
If you need to adjust the configuration based on whether watch mode is enabled, check process.argv:
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.
