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 the postcss-loader via tools.postcss.
Rsbuild has some builtin PostCSS plugins, which will perform the following transformations on CSS:
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.disableCssExtract 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.