CLI
Rsbuild comes with a lightweight CLI that includes commands such as rsbuild dev and rsbuild build.
rsbuild -h
To view all available CLI commands, run the following command in the project directory:
The output is shown below:
Usage: rsbuild <command> [options]
Options:
-V, --version output the version number
-h, --help display help for command
Commands:
dev [options] starting the dev server
build [options] build the app for production
preview [options] preview the production build locally
inspect [options] inspect the Rspack and Rsbuild configs
help [command] display help for command
rsbuild dev
The rsbuild dev
command is used to start a local dev server and compile the source code for development.
Usage: rsbuild dev [options]
Options:
-c --config <config> specify the configuration file, can be a relative or absolute path
-r --root <root> specify the project root directory, can be an absolute path or a path relative to cwd
-m --mode <mode> specify the build mode, can be `development`, `production` or `none`
-o, --open [url] open the page in browser on startup
--port <port> specify a port number for Rsbuild Server to listen
--host <host> specify the host that the Rsbuild Server listens to
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
--env-dir <dir> specify the directory to load `.env` files
--environment <name> specify the name of environment to build
-h, --help display help for command
Opening Page
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:
rsbuild dev --open http://localhost:3000/foo
The --open
option can also be abbreviated to -o
:
TIP
When using server.open and --open
at the same time, --open
takes precedence.
rsbuild build
The rsbuild build
command will build the outputs for production in the dist/
directory by default.
Usage: rsbuild build [options]
Options:
-c --config <config> specify the configuration file, can be a relative or absolute path
-r --root <root> specify the project root directory, can be an absolute path or a path relative to cwd
-m --mode <mode> specify the build mode, can be `development`, `production` or `none`
-w --watch turn on watch mode, watch for changes and rebuild
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
--env-dir <dir> specify the directory to load `.env` files
--environment <name> specify the name of environment to build
-h, --help display help for command
rsbuild preview
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.
Usage: rsbuild preview [options]
Options:
-c --config <config> specify the configuration file, can be a relative or absolute path
-r --root <root> specify the project root directory, can be an absolute path or a path relative to cwd
-m --mode <mode> specify the build mode, can be `development`, `production` or `none`
-o, --open [url] open the page in browser on startup
--port <port> specify a port number for Rsbuild Server to listen
--host <host> specify the host that the Rsbuild Server listens to
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
--env-dir <dir> specify the directory to load `.env` files
--environment <name> specify the name of environment to build
-h, --help display help for command
TIP
The preview command is only used for local preview. Do not use it for production servers, as it is not designed for that.
rsbuild inspect
The rsbuild inspect
command is used to view the Rsbuild config and Rspack config of the project.
Usage: rsbuild inspect [options]
Options:
-c --config <config> specify the configuration file, can be a relative or absolute path
-r --root <root> specify the project root directory, can be an absolute path or a path relative to cwd
-m --mode <mode> specify the build mode, can be `development`, `production` or `none`
--output <output> specify the path to output in the dist (default: ".rsbuild")
--verbose show the full function in the result
--env-mode <mode> specify the env mode to load the `.env.[mode]` file
--env-dir <dir> specify the directory to load `.env` files
--environment <name> specify the name of environment to build
-h, --help show command help
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.
➜ npx rsbuild inspect
Inspect config succeed, open following files to view the content:
- Rsbuild Config: /project/dist/.rsbuild/rsbuild.config.mjs
- Rspack Config (web): /project/dist/.rsbuild/rspack.config.web.mjs
Specifying Mode
By default, the inspect command outputs the configuration for the development mode. You can add the --env production
option to output the configuration for the production mode:
rsbuild inspect --mode production
Verbose content
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:
rsbuild inspect --verbose
Multiple Targets
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.
➜ npx rsbuild inspect
Inspect config succeed, open following files to view the content:
- Rsbuild Config (web): /project/dist/.rsbuild/rsbuild.config.web.mjs
- Rsbuild Config (node): /project/dist/.rsbuild/rsbuild.config.node.mjs
- Rspack Config (web): /project/dist/.rsbuild/rspack.config.web.mjs
- Rspack Config (node): /project/dist/.rsbuild/rspack.config.node.mjs