CC 4.0 License

The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.

The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.

Extends

Used to extend configurations from other files or packages. This allows you to create a base configuration and extend it for different environments or use cases.

  • Type: string | string[]
  • Default: undefined
Warning

This option is not supported via the Node API: Extends will have no effect when using the Node API. @rspack/cli is required to use this feature.

Basic Usage

You can extend a configuration from another file by specifying the path to the file in the extends property. The path can be absolute or relative to the configuration file:

rspack.config.js
module.exports = {
  extends: './base.rspack.config.js',
  // Override or add to the base configuration
  output: {
    path: path.resolve(__dirname, 'build'),
    filename: '[name].bundle.js',
  },
};
TIP

When using relative paths, they are resolved relative to the configuration file that contains the extends property.

Multiple Configurations

  • Type: string[]
  • Default: undefined

You can extend multiple configurations by providing an array of paths. Configurations are merged from right to left, meaning that the rightmost configuration will be merged into the leftmost one, and so on:

rspack.config.js
module.exports = {
  extends: ['./base.rspack.config.js', './dev.rspack.config.js'],
  // Additional configuration options
  plugins: [
    // Add more plugins
  ],
};
Merge Behavior

When merging configurations:

  • Simple values are overwritten
  • Arrays are concatenated
  • Objects are deeply merged

Node Modules

  • Type: string
  • Default: undefined

You can also extend configurations from packages installed in your node_modules. The package should export a valid Rspack configuration:

rspack.config.js
module.exports = {
  extends: 'some-rspack-config-package',
  // Override or add to the package's configuration
};

Nested Extends

Configurations can have their own extends property, allowing for nested configuration inheritance. The resolution is performed recursively:

base.rspack.config.js
module.exports = {
  extends: './core.rspack.config.js',
  // Base configuration options
};
rspack.config.js
module.exports = {
  extends: './base.rspack.config.js',
  // Environment-specific configuration options
};