boolean
false
Whether to inject styles into DOM.
By default, Rsbuild will extract CSS into a separate .css
file and output it to the dist directory. When this option is set to true
, CSS files will be inlined into JS files and inserted on the page at runtime via <style>
tags. This feature is implemented based on style-loader.
When output.injectStyles
is enabled, you can modify the options of style-loader
through tools.styleLoader.
It is recommended to only enable the injectStyles
option during development.
For production builds, it is recommended to use the default behavior of Rsbuild, which extracts CSS into separate bundles to allow browsers to load CSS and JS assets in parallel.
For example:
If you need to enable this option in the production build, please note that the inlined CSS code will not go through Rsbuild's default CSS minimizer. You can manually register the cssnano plugin for PostCSS to compress the inlined code.
tools.postcss
: