Used to set whether to generate source map files, and which format of source map to generate.
Source map is an information file that saves the source code mapping relationship. It records each location of the compiled code and the corresponding pre-compilation location. With source map, you can directly view the source code when debugging the compiled code.
By default, the source map generation rules for Rsbuild are as follows:
If output.sourceMap
is true
, the source map will be generated according to the mode, equivalent to:
If output.sourceMap
is false
, no source map will be generated, equivalent to:
The source map for JS files is controlled by sourceMap.js
and can be configured by passing in all the source map formats supported by Rspack's devtool option. Setting it to false
will disable the source map.
For example, if you need to generate high-quality source maps in all environments, you can set it as follows:
You can also set different source map formats based on the environment.
The source map for CSS files is controlled by sourceMap.css
. Setting it to true
will enable the source map, while setting it to false
will disable it.
For example, if you need to generate a source map for CSS files, you can set it as follows:
In production builds, it is not recommended to enable both output.injectStyles and output.sourceMap.css
, as output.injectStyles
will inject the source map into the JS bundles, which will increase the file size and slow down the page loading speed.
You can only enable the CSS file source map in the development mode: