Rslib comes with a lightweight CLI that includes commands such as rslib build and rslib inspect.
To view all available CLI commands, run the following command in the project directory:
The output is shown below:
Rslib CLI provides several common flags that can be used with all commands:
Flag | Description |
---|---|
-c, --config <config> | Specify the configuration file, can be a relative or absolute path, see Specify config file |
--env-dir <dir> | Specify the directory to load .env files, see Rsbuild - Env directory |
--env-mode <mode> | Specify the env mode to load the .env.[mode] file, see Rsbuild - Env mode |
-h, --help | Display help for command |
--lib <id> | Specify the library to run commands (repeatable, e.g. --lib esm --lib cjs ), see lib.id to learn how to get or set the ID of the library |
-r, --root <root> | Specify the project root directory, can be an absolute path or a path relative to cwd |
The rslib build
command will build the outputs for production in the dist/
directory by default.
Rslib supports injecting env variables or expressions into the code during build, which is helpful for distinguishing the running environment or replacing constants.
You can see more details in Rsbuild - Environment variables.
The rslib inspect
command is used to view the Rsbuild config and Rspack config of the Rslib project.
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.web.mjs
: Represents the Rspack configuration used during the build.By default, the inspect command omits the content of functions in the configuration object. You can add the --verbose
option to output the complete content of functions:
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.
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.