For AI agents: the complete documentation index is available at https://rspack.rs/llms.txt, the full documentation bundle is available at https://rspack.rs/llms-full.txt, and this page is available as Markdown at https://rspack.rs/config/extends.md.
close

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.

ESM
CJS
rspack.config.mjs
export default {
  extends: './base.rspack.config.mjs',
  output: {
    filename: '[name].bundle.js',
  },
};

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.

rspack.config.mjs
export default {
  extends: ['./dev.config.mjs', './web.config.mjs'],
  output: {
    filename: '[name].js',
  },
};

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 from dev.config.mjs wins. Set mode in rspack.config.mjs to override both.
  • Objects. Properties merge recursively. Setting output.filename overrides the inherited filename while preserving other properties such as output.publicPath.
  • Arrays. Entries in arrays such as plugins and module.rules are concatenated in merge order. Plugins from web.config.mjs come first, followed by those from dev.config.mjs and then rspack.config.mjs.

Node modules

To extend a configuration from an installed package, use its package name. The package must export a Rspack configuration.

rspack.config.mjs
export default {
  extends: 'some-rspack-config-package',
};

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.

dev.config.mjs
export default {
  extends: './shared.mjs',
  mode: 'development',
};

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.