Rsbuild includes a lightweight CLI with commands like rsbuild dev and rsbuild build.
To view all available CLI commands, run this command in your project directory:
The output is shown below:
The Rsbuild CLI includes several common flags that work with all commands:
Flag | Description |
---|---|
--base <base> | Set the base path of the server, see server.base |
-c, --config <config> | Set the configuration file (relative or absolute path), see Specify config file |
--config-loader <loader> | Set the config file loader (auto | jiti | native ), see Specify config loader |
--env-mode <mode> | Set the env mode to load the .env.[mode] file, see Env mode |
--env-dir <dir> | Set the directory for loading .env files, see Env directory |
--environment <name> | Set the environment name(s) to build, see Build specified environment |
-h, --help | Display help for command |
--log-level <level> | Set the log level (info | warn | error | silent ), see logLevel |
-m, --mode <mode> | Set the build mode (development | production | none ), see mode |
--no-env | Disable loading of .env files |
-r, --root <root> | Set the project root directory (absolute path or relative to cwd) |
The rsbuild dev
command starts a local dev server and compiles source code for development.
Start the dev server by running rsbuild
directly, which is equivalent to rsbuild dev
:
The --open
option automatically opens a page when starting the dev server, equivalent to setting server.open to true
.
The --open
option also supports specifying a URL to open, for example:
The --open
option can also be abbreviated to -o
:
When using server.open and --open
at the same time, --open
takes precedence.
The rsbuild build
command builds production outputs in the dist/
directory by default.
The rsbuild preview
command previews production build outputs locally. Run rsbuild build
first to generate the build outputs.
The preview command is only used for local preview. Do not use it for production servers, as it is not designed for that.
The rsbuild inspect
command displays the project's Rsbuild and Rspack configurations.
Running npx rsbuild inspect
in the project root generates these files in the dist/.rsbuild
directory:
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 outputs the configuration for the development mode. You can add the --mode production
option to output the configuration for the production mode:
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 build targets, such as building browser bundles and Node.js bundles simultaneously, multiple Rspack configuration files will be generated in the dist/.rsbuild
directory.