Configure Rspack
Rsbuild supports directly modifying the Rspack configuration object, and supports modifying the built-in Rspack configuration of Rsbuild through rspack-chain.
The built-in Rspack config in Rsbuild may change with iterations, and these changes will not be reflected in semver. Therefore, your custom config may become invalid when you upgrade Rsbuild.
View Rspack config
Rsbuild provides the rsbuild inspect command to view the final Rspack config generated by Rsbuild.
You can also view it through debug mode.
Modify config object
You can use the tools.rspack option of Rsbuild to modify the Rspack config object.
For example, registering a built-in Rspack plugin:
Or registering a community webpack plugin:
Or modify the built-in Rspack config with a function:
Please refer to the tools.rspack documentation for detailed usage.
Access Rspack API
If you need to access the API or plugins exported by @rspack/core, you can directly import the rspack object from @rsbuild/core without installing the @rspack/core package separately.
- Refer to Rspack plugins and Rspack JavaScript API to learn more about the available Rspack APIs.
- It's not recommended to manually install the
@rspack/corepackage, as it may conflict with the version that Rsbuild depends on.
Use bundler chain
rspack-chain is a utility library for configuring Rspack. It provides a chaining API, making the configuration of Rspack more flexible. By using rspack-chain, you can more easily modify and extend Rspack configurations without directly manipulating the complex configuration object.
tools.bundlerChain
Rsbuild provides the tools.bundlerChain config to modify the rspack-chain. Its value is a function that takes two arguments:
- The first argument is an
rspack-chaininstance, which you can use to modify the Rspack config. - The second argument is an utils object, including
env,isProd,CHAIN_ID, etc.
Here is a basic example:
tools.bundlerChain can also be an async function:
Basics
Before using the rspack-chain to modify the Rspack configuration, it is recommended to familiarize yourself with some basics.
About ID
In short, the rspack-chain requires users to set a unique ID for each rule, loader, plugin, and minimizer. With this ID, you can easily find the desired object from deeply nested objects.
Rsbuild exports all internally defined IDs through the CHAIN_ID object, so you can quickly locate the loader or plugin you want to modify using these exported IDs, without the need for complex traversal in the Rspack configuration object.
For example, you can remove the built-in CSS rule using CHAIN_ID.RULE.CSS:
ID types
The CHAIN_ID object contains various IDs, which correspond to the following configurations:
Examples
Custom loader
Here are examples of adding, modifying, and removing Rspack loaders.
- Add a loader to handle
.mdfiles:
- Modify options of the built-in SWC loader:
- Remove the built-in SWC loader:
- Insert a loader after the built-in SWC loader that executes earlier:
Note: Rspack loaders are executed in reverse order.
- Insert a loader before the built-in SWC loader that executes later:
- Remove the built-in CSS handling rule:
Custom plugin
Here are examples of adding, modifying, and deleting Rspack plugins.
In most cases, you should change the plugin options using the configurations provided by Rsbuild, rather than using CHAIN_ID.PLUGIN, as this may lead to unexpected behavior.
For example, use tools.htmlPlugin to change the options of HtmlPlugin.
Modify based on environment
In the tools.bundlerChain function, you can access various environment identifiers in the second parameter, such as development/production build, SSR build, Web Worker build, to achieve configuration modifications for different environments.
The above are some common configuration examples. For the complete rspack-chain API, please refer to the rspack-chain documentation.
Configuration modification order
Rsbuild supports modifying the Rspack configuration object through tools.rspack, tools.bundlerChain, modifyBundlerChain, etc.
The order of execution between them is:

