Default: undefined
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.
You can use rspack-chain to modify the default Rspack config through tools.bundlerChain
. Its value is a function that takes two arguments:
rspack-chain
instance, which you can use to modify the Rspack config.env
, isProd
, CHAIN_ID
, etc.
tools.bundlerChain
will be executed earlier than tools.rspack, so it will be overridden bytools.rspack
.
The built-in Rspack config in Rsbuild may change with iterations, and these changes won't be reflected in semver. Therefore, your custom config may become invalid when you upgrade Rsbuild.
Please refer to: RspackChain examples.
'development' | 'production' | 'test'
The env
parameter can be used to determine whether the current environment is development, production or test. For example:
boolean
Used to determine whether the current build is a development build, such as:
boolean
Used 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:
boolean
Determines whether the target environment is node
, equivalent to target === 'node'
.
boolean
Determines whether the target environment is web-worker
, equivalent to target === 'web-worker'
.
typeof import('html-webpack-plugin')
The instance of html-webpack-plugin
:
Some common Chain IDs are predefined in the Rsbuild, and you can use these IDs to locate the built-in Rule or Plugin.
Please note that some of the rules or plugins listed below are not available by default. They will only be included in the Rspack or webpack configuration when you enable specific options or register certain plugins.
For example, the RULE.STYLUS
rule exists only when the Stylus plugin is registered.
ID | Description |
---|---|
RULE.JS |
Rule for js and ts |
RULE.SVG |
Rule for svg |
RULE.CSS |
Rule for css |
RULE.LESS |
Rule for less |
RULE.SASS |
Rule for sass |
RULE.YAML |
Rule for yaml |
RULE.WASM |
Rule for WASM |
RULE.NODE |
Rule for node |
RULE.FONT |
Rule for font |
RULE.IMAGE |
Rule for image |
RULE.MEDIA |
Rule for media |
RULE.VUE |
Rule for vue (requires Vue plugin) |
RULE.SVELTE |
Rule for svelte (requires Svelte plugin) |
RULE.STYLUS |
Rule for stylus (requires Stylus plugin) |
ONE_OF.[ID]
can match a certain type of rule in the rule array.
ID | Description |
---|---|
ONE_OF.SVG_URL |
Rules for SVG, output as a separate file |
ONE_OF.SVG_INLINE |
Rules for SVG, inlined into bundles as data URIs |
ONE_OF.SVG_ASSETS |
Rules for SVG, automatic choice between data URI and separate file |
USE.[ID]
can match a certain loader.
ID | Description |
---|---|
USE.SWC |
correspond to swc-loader |
USE.LESS |
correspond to less-loader |
USE.SASS |
correspond to sass-loader |
USE.YAML |
correspond to yaml-loader |
USE.NODE |
correspond to node-loader |
USE.STYLE |
correspond to style-loader |
USE.POSTCSS |
correspond to postcss-loader |
USE.RESOLVE_URL |
correspond to resolve-url-loader |
USE.VUE |
correspond to vue-loader (requires Vue plugin) |
USE.SVGR |
correspond to svgr-loader (requires Svgr plugin) |
USE.BABEL |
correspond to babel-loader (requires Babel plugin) |
USE.SVELTE |
correspond to svelte-loader (requires Svelte plugin) |
USE.STYLUS |
correspond to stylus-loader (requires Stylus plugin) |
PLUGIN.[ID]
can match a certain Rspack or Webpack plugin.
ID | Description |
---|---|
PLUGIN.HTML |
correspond to HtmlPlugin , you need to concat the entry name when using: ${PLUGIN.HTML}-${entryName} |
PLUGIN.APP_ICON |
correspond to AppIconPlugin |
PLUGIN.INLINE_HTML |
correspond to InlineChunkHtmlPlugin |
PLUGIN.ASSETS_RETRY |
correspond to AssetsRetryPlugin |
PLUGIN.BUNDLE_ANALYZER |
correspond to WebpackBundleAnalyzer |
PLUGIN.VUE_LOADER_PLUGIN |
correspond to VueLoaderPlugin |
PLUGIN.AUTO_SET_ROOT_SIZE |
correspond to AutoSetRootSizePlugin |
MINIMIZER.[ID]
can match a certain minimizer.
ID | Description |
---|---|
MINIMIZER.JS |
correspond to SwcJsMinimizerRspackPlugin |
MINIMIZER.CSS |
correspond to SwcCssMinimizerRspackPlugin |