Rspack.Configuration | Function | undefinedundefinedtools.rspack is used to configure Rspack.
tools.rspack can be configured as an object to be deep merged with the built-in Rspack configuration through webpack-merge.
For example, add resolve.alias configuration:
tools.rspack can be configured as a function. The first parameter of this function is the built-in Rspack configuration object, you can modify this object, and then return it. For example:
The object returned by the tools.rspack function is used directly as the final Rspack configuration and is not merged with the built-in Rspack configuration.
The second parameter of this function is an object, which contains some utility functions and properties, as follows:
'development' | 'production' | 'test'The env parameter can be used to determine whether the current environment is development, production or test. For example:
booleanUsed to determine whether the current build is a development build, such as:
booleanUsed to determine whether the current build is a production build, such as:
'web' | 'node' | 'web-worker' | 'service-worker'The target parameter can be used to determine the build target environment. For example:
booleanDetermines whether the target environment is node, equivalent to target === 'node'.
booleanDetermines whether the target environment is web-worker, equivalent to target === 'web-worker'.
RspackThe Rspack instance. For example:
(rules: RuleSetRule | RuleSetRule[]) => voidAdd additional Rspack rules.
For example:
(plugins: BundlerPluginInstance | BundlerPluginInstance[]) => voidAdd additional plugins to the head of the internal Rspack plugins array, and the plugin will be executed first.
(plugins: BundlerPluginInstance | BundlerPluginInstance[]) => voidAdd additional plugins at the end of the internal Rspack plugins array, the plugin will be executed last.
(name: string) => voidRemove the internal Rspack plugin, the parameter is the constructor.name of the plugin.
For example, remove the internal webpack-bundle-analyzer:
(...configs: RspackConfig[]) => RspackConfigUsed to merge multiple Rspack configs, same as webpack-merge.
The mergeConfig method will create a new config object without modifying the original config object, so you need to return the result of mergeConfig.