Rsbuild comes with a lightweight CLI that includes commands such as rsbuild dev and rsbuild build.
To view all available CLI commands, run the following command in the project directory:
The output is shown below:
Rsbuild CLI provides several common flags that can be used 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 Set config file |
--config-loader <loader> | Set the config file loader (jiti | native ), see Set 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 is used to start a local dev server and compile the source code for development.
You can also start the dev server by running rsbuild
directly, which is equivalent to running rsbuild dev
.
The --open
option allows you to automatically open a page when starting the dev server, which is equivalent to setting server.open to true
.
The --open
option also supports specifying the URL to be opened, 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 will build the outputs for production in the dist/
directory by default.
The rsbuild preview
command is used to preview the production build outputs locally. Note that you need to execute the rsbuild build
command beforehand 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 is used to view the Rsbuild config and Rspack config of the project.
When you run the command npx rsbuild 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 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 artifact and Node.js artifact simultaneously, multiple Rspack configuration files will be generated in the dist/.rsbuild
directory.