Extends
Use extends to share a base configuration across projects or between development and production builds. For example, both builds can inherit the same loaders and plugins while setting their own mode and devtool options.
- Type:
string | string[] - Default:
undefined
extends is available only in @rspack/cli. If you use the JavaScript API or another Rspack-based tool, you can merge your configurations with rspack-merge.
Basic usage
Set extends to an absolute or relative path. The CLI resolves relative paths from the directory of the file that declares extends. Your base configuration can also be a JSON file, such as ./base.rspack.config.json.
Multiple configurations
To extend several configurations, list them in an array. The CLI uses rspack-merge to combine them from right to left, with the current configuration applied last.
In this example, the merge order is web.config.mjs, then dev.config.mjs, then rspack.config.mjs.
- Simple values. If both base files set
mode, the value fromdev.config.mjswins. Setmodeinrspack.config.mjsto override both. - Objects. Properties merge recursively. Setting
output.filenameoverrides the inherited filename while preserving other properties such asoutput.publicPath. - Arrays. Entries in arrays such as
pluginsandmodule.rulesare concatenated in merge order. Plugins fromweb.config.mjscome first, followed by those fromdev.config.mjsand thenrspack.config.mjs.
Node modules
To extend a configuration from an installed package, use its package name. The package must export a Rspack configuration.
Nested extends
A base configuration can extend another configuration. In the example above, dev.config.mjs can inherit shared settings and add its own development options.
If web.config.mjs also extends shared.mjs, the final configuration inherits the shared settings through both files. This registers each plugin from shared.mjs twice. To register a plugin once, move it from shared.mjs to rspack.config.mjs.
The CLI reports a cycle if a file extends itself, directly or through other files. For example, Circular extends chain: dev.config.mjs -> shared.mjs -> dev.config.mjs means the two files extend each other. Remove one of those references to break the cycle.
This page is adapted from webpack documentation under the CC BY 4.0, with modifications.

