Rsbuild has built-in multiple style resource processing capabilities, including Less / Sass preprocessor, PostCSS, CSS Modules, CSS inline and CSS compression.
In addition, Rsbuild also provides multiple configs to customize the compile rules of style resources.
The Rsbuild has built-in community popular CSS preprocessors such as Less, Sass.
By default, you don't need to configure anything for Less and Sass. If you need to customize loader config, you can configure tools.less, tools.sass to set it up.
You can also use Stylus in Rsbuild, just install the Stylus plugin provided by Rsbuild, please refer to Stylus Plugin for usage.
Rsbuild has built-in PostCSS to transform the CSS code. You can configure PostCSS in the following ways:
postcss.config.js
:When you configure both the postcss.config.js
file and the tools.postcss
option, both will take effect, and the tools.postcss
option will take precedence.
Rsbuild has built-in autoprefixer plugin, which is used to add vendor prefixes to CSS rules. If you need to configure the target browser, you can use browserslist.
If the autoprefixer plugin is already registered in your project, Rsbuild will not register the autoprefixer plugin again.
Please read the Using CSS Modules chapter for a complete usage of CSS Modules.
During the production build, Rsbuild compresses static assets such as CSS and JS to provide better transmission efficiency.
Rsbuild by default uses the built-in SwcCssMinimizerRspackPlugin
plugin from Rspack to automatically compress CSS code during production builds.
You can customize the CSS minimizer by using the CSS Minimizer plugin to switch to cssnano or other tools for CSS compression.
By default, Rsbuild will extract CSS into a separate .css
file and output it to the dist directory.
If you want to inline styles into your JS file, you can set output.injectStyles to true to disable CSS extraction logic. When the JS file is requested by the browser, JS dynamically inserts the <style>
tag into the Html to load the CSS styles.
This will increase the size of your JS Bundle, so it is usually not recommended to disable the CSS extraction.
You can directly import CSS files in node_modules.