Configures whether to generate source map files and which source map format to generate.
A source map is an information file that stores the source code mapping relationship. It records each location of the compiled code and the corresponding pre-compilation location. With source maps, you can directly view the source code when debugging compiled code.
By default, Rsbuild generates source maps using these rules:
If output.sourceMap
is true
, source maps 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, to generate high-quality source maps in all environments:
You can also set different source map formats based on the environment.
Do not deploy source maps (.map
files) to the public web server or CDN when using values such as source-map
or hidden-source-map
in production builds. Public source maps will expose your source code and may bring security risks.
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.
To generate a source map for CSS files:
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 development mode: