The Rsbuild by default uses the SWC built-in by Rspack to minify CSS code. You can customize the CSS minimizer by using the CSS Minimizer plugin and switch to cssnano or other tools for CSS minification.
The CSS Minimizer plugin internally integrates css-minimizer-webpack-plugin.
cssnano is a tool for optimizing and minifying CSS files. It reduces the size of CSS files by removing unused rules, merging similar rules, removing comments and whitespace, and converting length units, among other techniques, to improve the loading speed of websites.
You can install the plugin using the following command:
You can register the plugin in the rsbuild.config.ts
file:
Used to customize the options of css-minimizer-webpack-plugin.
The value of pluginOptions
will be merged with the default options inside the plugin using Object.assign
and then passed to the css-minimizer-webpack-plugin. You can refer to the README documentation of css-minimizer-webpack-plugin to explore all available options.
Object | Function | undefined
preset
configuration of cssnano.