--- description: 'Rsbuild includes a lightweight CLI with commands like rsbuild dev and rsbuild build.' --- # CLI Rsbuild includes a lightweight CLI with commands like [rsbuild dev](#rsbuild) and [rsbuild build](#rsbuild-build). ## All commands To view all available CLI commands, run this command in your project directory: ```bash npx rsbuild -h ``` The output is shown below: ``` Usage: $ rsbuild [command] [options] Commands: dev Start the dev server build Build the app for production preview Preview the production build locally inspect Inspect the Rspack and Rsbuild configurations ``` ## Common flags The Rsbuild CLI includes several common flags that work with all commands: | Flag | Description | | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `--base ` | Set the base path of the server, see [server.base](/config/server/base) | | `-c, --config ` | Set the configuration file (relative or absolute path), see [Specify config file](/guide/configuration/rsbuild#specify-config-file) | | `--config-loader ` | Set the config file loader (`auto` \| `jiti` \| `native`), see [Specify config loader](/guide/configuration/rsbuild#specify-config-loader) | | `--dist-path ` | Set the root directory of output files, see [output.distPath](/config/output/dist-path) | | `--env-mode ` | Set the env mode to load the `.env.[mode]` file, see [Env mode](/guide/advanced/env-vars#env-mode) | | `--env-dir ` | Set the directory for loading `.env` files, see [Env directory](/guide/advanced/env-vars#env-directory) | | `--environment ` | Set the environment name(s) to build, see [Build specified environment](/guide/advanced/environments#build-a-specific-environment) | | `-h, --help` | Display help for command | | `--log-level ` | Set the log level (`info` \| `warn` \| `error` \| `silent`), see [logLevel](/config/log-level) | | `-m, --mode ` | Set the build mode (`development` \| `production` \| `none`), see [mode](/config/mode) | | `--no-env` | Disable loading of `.env` files | | `--no-source-map` | Disable source maps, see [output.sourceMap](/config/output/source-map) | | `-r, --root ` | Set the project root directory (absolute path or relative to [cwd](https://nodejs.org/api/process.html#processcwd)) | | `--source-map` | Enable source maps, see [output.sourceMap](/config/output/source-map) | For boolean flags, the `--no-` prefix can be used to explicitly disable the corresponding feature, such as `--no-env` or `--no-source-map`. ## rsbuild The `rsbuild` command starts a local dev server and compiles source code for development. `rsbuild dev` is an alias for `rsbuild`. ```bash Usage: rsbuild [options] rsbuild dev [options] Options: -o, --open [url] Open the page in browser on startup --port Set the port number for the server --strict-port Exit if the specified port is already in use --host [host] Set the host that the server listens to ``` ### Specifying host By default, the dev server listens on `localhost`. Passing `--host` without a value will make the server listen on all network interfaces: ```bash npx rsbuild --host # equivalent to: npx rsbuild --host 0.0.0.0 ``` ### Opening page The `--open` option opens a page automatically when the dev server starts (equivalent to setting [server.open](/config/server/open) to `true`). ```bash rsbuild --open ``` The `--open` option also accepts a specific URL to open. For example: ```bash rsbuild --open http://localhost:3000/foo ``` The `--open` option can also be abbreviated to `-o`: ```bash rsbuild -o ``` :::tip When using both [server.open](/config/server/open) and `--open`, the `--open` option takes precedence. ::: ## rsbuild build The `rsbuild build` command builds production outputs in the `dist/` directory by default. ```bash Usage: rsbuild build [options] Options: -w, --watch Enable watch mode to automatically rebuild on file changes ``` ## rsbuild preview The `rsbuild preview` command previews production build outputs locally. You must run `rsbuild build` first to generate the outputs. ```bash Usage: rsbuild preview [options] Options: -o, --open [url] Open the page in browser on startup --port Set a port number for Rsbuild server to listen --strict-port Exit if the specified port is already in use --host [host] Set the host that the Rsbuild server listens to ``` :::tip Use the preview command only for local previews. Do not use it in production, as it is not designed for production servers. ::: ## rsbuild inspect The `rsbuild inspect` command displays the project's Rsbuild and Rspack configurations. ```bash Usage: rsbuild inspect [options] Options: --output Set the output path for inspection results (default: ".rsbuild") --verbose Show complete function definitions in output ``` Running `npx rsbuild inspect` in the project root generates the following 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. ```bash ➜ npx rsbuild inspect config inspection completed, generated files: - Rsbuild config: /project/dist/.rsbuild/rsbuild.config.mjs - Rspack config (web): /project/dist/.rsbuild/rspack.config.web.mjs ``` ### Setting mode By default, the inspect command outputs configuration for development mode. To output production mode configuration, add the `--mode production` option: ```bash rsbuild inspect --mode production ``` ### Verbose content By default, the inspect command omits function bodies in the configuration object. To output complete function content, add the `--verbose` option: ```bash rsbuild inspect --verbose ``` ### Multiple targets If the current project has multiple build targets (such as building both browser and Node.js bundles), multiple Rspack configuration files will be generated in the `dist/.rsbuild` directory. ```bash ➜ npx rsbuild inspect config inspection completed, generated files: - 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 ```