trueConfigure whether to enable code minification in production mode, and to configure minimizer options.
By default, JS and CSS code will be automatically minimized in production mode to improve page performance. If you do not want to minify the code, you can set minify to false to disable minification for all code. Alternatively, you can control the behavior of code minification through detailed configuration of the minify option. Below are detailed explanations for each configuration option:
Rsbuild uses SWC to minify JS code and Lightning CSS to minify CSS code by default.
Set minify to false to disable JS and CSS code minification:
This usage is usually used for debugging and troubleshooting. It is not recommended to disable code minification in production builds, as it will significantly degrade the page performance.
boolean | 'always'trueWhether to enable minification for JavaScript bundles:
true: Enabled in production mode.false: Disabled in all modes.'always': Enabled in all modes.For example, disable JavaScript minification:
Enable JavaScript minification in both development and production mode:
Rspack.SwcJsMinimizerRspackPluginOptions{}output.minify.jsOptions is used to configure SWC's minification options. For detailed configurations, please refer to SwcJsMinimizerRspackPlugin. The following configuration will override the default settings, disable the mangle feature.
For example, disable the mangle feature:
Refer to Configure SWC for more details.
boolean | 'always'trueWhether to enable minification for CSS bundles:
true: Enabled in production mode.false: Disabled in all modes.'always': Enabled in all modes.For example, disable CSS minification:
Enable CSS minification in both development and production mode:
Rspack.LightningcssMinimizerRspackPluginOptionsoutput.minify.cssOptions is used to configure Lightning CSS's minification options. For detailed configuration options, please refer to LightningCssMinimizerRspackPlugin Documentation.
For example, disable error recovery:
When you configure some options in tools.lightningcssLoader, output.minify.cssOptions will automatically inherit these options, which ensures that the CSS code transformation behavior in the development build is consistent with that in the production build.
If the default SWC minifier does not meet your needs, you can switch to other minifiers through the tools.bundlerChain option.
For example, use terser-webpack-plugin to switch to Terser or esbuild.
esbuild package and set esbuildMinify:
When using a custom JS minifier, the minify.jsOptions option will no longer take effect.