Command line interface

@rspack/cli is the command line tool for Rspack, providing a variety of commands to make working with Rspack easier.

  • If you do not have @rspack/cli installed, please read the Quick start section first.
  • If you are using Rsbuild, please refer to the Rsbuild CLI section.
Compatible with webpack-cli

@rspack/cli is not compatible with webpack-cli, so there will be some differences between the two.

rspack build

rspack build is used to run Rspack build, which will generate the output files in the output.path directory.

npx rspack build  # Read the `rspack.config.*` configuration file by default

rspack build can be abbreviated as rspack b:

npx rspack b

Use the -c or --config flag to specify the configuration file path:

npx rspack build -c ./your.config.js

The complete flags are as follows:

rspack build Options: --entry entry file [array] -o, --output-path output path dir [string] -m, --mode mode [string] -w, --watch watch [boolean] [default: false] --env env passed to config function [array] --node-env sets process.env.NODE_ENV to be specified value [string] -d, --devtool devtool [boolean] [default: false] --configName Name of the configuration to use. [array] --analyze analyze [boolean] [default: false] --json emit stats json --profile capture timing information for each module [boolean] [default: false]

rspack dev

rspack dev is used to run Rspack dev server, which will start a local dev server that will listen for file changes and automatically refresh the browser.

npx rspack dev

Use the -c or --config flag to specify the configuration file path:

npx rspack dev -c ./your.config.js

rspack dev can be abbreviated as rspack serve or rspack s:

npx rspack s
npx rspack serve

The complete flags are as follows:

rspack dev Options: --entry entry file [array] -o, --output-path output path dir [string] -m, --mode mode [string] -w, --watch watch [boolean] [default: false] --env env passed to config function [array] --node-env sets process.env.NODE_ENV to be specified value [string] -d, --devtool devtool [boolean] [default: false] --configName Name of the configuration to use. [array] --hot enables hot module replacement --port allows to specify a port to use [number] --host allows to specify a hostname to use [string]

rspack preview

rspack preview is used to preview the production build output locally, note that you need to build the output first by running the rspack build command.

npx rspack preview

The complete flags are as follows:

rspack preview [dir] run the rspack server for build output Positionals: dir directory want to preview [string] Options: --help Show help [boolean] --version Show version number [boolean] --publicPath static resource server path [string] -c, --config config file [string] --port preview server port [number] --host preview server host [string] --open open browser [boolean] --server Configuration items for the server. [string] --configName Name of the configuration to use. [array]

Common Flags

Here are some common flags that are supported by all Rspack commands:

Flags Usage
-c, --config [value] Specify the path to the configuration file
-h, --help Show help information
-v, --version Show version number