Configure Rsbuild
Rsbuild provides a wide range of configuration options with sensible defaults for most use cases. In most scenarios, you can use Rsbuild out of the box without any configuration.
When you need to customize build behavior, use these configuration options.
Configuration structure
The configuration structure of Rsbuild looks like this:
You can find detailed descriptions of all configs on the Configure Overview page.
Configuration file
When you use the Rsbuild CLI, it automatically reads the configuration file in the root directory of the current project and resolves it in the following order:
- rsbuild.config.mjs
- rsbuild.config.ts
- rsbuild.config.js
- rsbuild.config.cjs
- rsbuild.config.mts
- rsbuild.config.cts
We recommend using rsbuild.config.ts and importing the defineConfig utility from @rsbuild/core. It provides friendly TypeScript type hints and autocompletion, which can help you avoid errors in the configuration.
For example, in rsbuild.config.ts, you can define the Rsbuild resolve.alias configuration:
If you are developing a non-TypeScript project, you can use the .mjs format for the configuration file:
Specify config file
Rsbuild CLI uses the --config option to specify the config file. It can be set to a relative or absolute path.
For example, if you need to use the rsbuild.prod.config.mjs file when running build, add the following scripts to package.json:
You can also abbreviate the --config option to -c:
Specify config loader
Rsbuild provides three ways to load configuration files:
-
auto(Default): Use Node.js's native loader to load configuration files first, falling back to jiti if it fails. -
jiti: Use jiti to load the configuration file, providing interoperability between ESM and CommonJS. The module resolution behavior differs slightly from Node.js native behavior. -
native: Use Node.js native loader to load the configuration file. This ensures that module resolution behavior is consistent with Node.js native behavior and has better performance. This requires your JavaScript runtime to natively support TypeScript.For example, Node.js v22.6.0+ natively supports TypeScript. You can use the following command with the Node.js native loader to load the configuration file:
About Node.js native loader
When using Node.js's native loader, please note the following limitations:
-
When importing JSON files, you need to use import attributes:
-
When importing TypeScript files, you need to include the
.tsextension:
See Node.js - Running TypeScript Natively for more details.
Using environment variables
In the configuration file, you can use Node.js environment variables such as process.env.NODE_ENV to dynamically set different configurations:
Export function
Rsbuild supports exporting a function in the config file, which allows you to dynamically compute the config and return it to Rsbuild.
The exported config function must provide a return value. If you do not need to return any config, you can return an empty object.
The function accepts the following parameters:
env
- Type:
string - Default:
process.env.NODE_ENV
The current running environment.
- When running
rsbuild dev, the default value of env isdevelopment. - When running
rsbuild buildorrsbuild preview, the default value of env isproduction.
envMode
- Type:
string - Default:
process.env.NODE_ENV
The current value of the CLI parameter --env-mode.
For example, when running rsbuild build --env-mode test, the value of envMode is test.
command
- Type:
string
The current running CLI command, such as dev, build, preview.
Export async function
Rsbuild also supports exporting an async function in the config file, which allows you to perform async operations:
Merge configurations
You can use the mergeRsbuildConfig function exported by @rsbuild/core to merge multiple configurations.
Debug the config
You can enable Rsbuild's debug mode by adding the DEBUG=rsbuild environment variable when executing a build.
In debug mode, Rsbuild will write the Rsbuild config to the dist directory, which is convenient for developers to view and debug.
Open the generated /dist/.rsbuild/rsbuild.config.mjs file to see the complete content of the Rsbuild config.
For a complete introduction to debug mode, see the Debug Mode chapter.

