close
logologo
Guide
Config
Plugin
API
Community
Version
Changelog
Rsbuild 0.x Doc
English
简体中文
Guide
Config
Plugin
API
Community
Changelog
Rsbuild 0.x Doc
English
简体中文
logologo
Overview
root
mode
plugins
logLevel
environments

dev

dev.assetPrefix
dev.browserLogs
dev.cliShortcuts
dev.client
dev.hmr
dev.lazyCompilation
dev.liveReload
dev.progressBar
dev.setupMiddlewares
dev.watchFiles
dev.writeToDisk

resolve

resolve.aliasStrategy
resolve.alias
resolve.conditionNames
resolve.dedupe
resolve.extensions
resolve.mainFields

source

source.assetsInclude
source.decorators
source.define
source.entry
source.exclude
source.include
source.preEntry
source.transformImport
source.tsconfigPath

output

output.assetPrefix
output.charset
output.cleanDistPath
output.copy
output.cssModules
output.dataUriLimit
output.distPath
output.emitAssets
output.emitCss
output.externals
output.filenameHash
output.filename
output.injectStyles
output.inlineScripts
output.inlineStyles
output.legalComments
output.manifest
output.minify
output.module
output.overrideBrowserslist
output.polyfill
output.sourceMap
output.target

html

html.appIcon
html.crossorigin
html.favicon
html.inject
html.meta
html.mountId
html.outputStructure
html.scriptLoading
html.tags
html.templateParameters
html.template
html.title

server

server.base
server.compress
server.cors
server.headers
server.historyApiFallback
server.host
server.htmlFallback
server.https
server.middlewareMode
server.open
server.port
server.printUrls
server.proxy
server.publicDir
server.strictPort

security

security.nonce
security.sri

tools

tools.bundlerChain
tools.cssExtract
tools.cssLoader
tools.htmlPlugin
tools.lightningcssLoader
tools.postcss
tools.rspack
tools.styleLoader
tools.swc

performance

performance.buildCache
performance.bundleAnalyze
performance.chunkSplit
performance.dnsPrefetch
performance.preconnect
performance.prefetch
performance.preload
performance.printFileSize
performance.profile
performance.removeConsole
performance.removeMomentLocale

moduleFederation

moduleFederation.options
📝 Edit this page on GitHub
Previous Pageoutput.polyfill
Next Pageoutput.target

#output.sourceMap

  • Type:
type SourceMap =
  | boolean
  | {
      js?: Rspack.Configuration['devtool'];
      css?: boolean;
    };
  • Default:
const defaultSourceMap = {
  js: mode === 'development' ? 'cheap-module-source-map' : false,
  css: false,
};

Configures whether to generate source map files and which source map format to generate.

What is a source map

A source map is an information file that stores source code mapping relationships. It records each location of the compiled code and its corresponding pre-compilation location. With source maps, you can directly view source code when debugging compiled code.

#Default behavior

Rsbuild generates source maps using these rules by default:

  • In development mode, source maps for JS files are generated for development debugging, while source maps for CSS files are not generated.
  • In production mode, source maps for JS and CSS files are not generated to improve build performance.

#Boolean value

If output.sourceMap is true, source maps are generated according to the mode, equivalent to:

export default {
  output: {
    sourceMap: {
      js: mode === 'development' ? 'cheap-module-source-map' : 'source-map',
      css: true,
    },
  },
};

If output.sourceMap is false, no source map will be generated, equivalent to:

export default {
  output: {
    sourceMap: {
      js: false,
      css: false,
    },
  },
};

#JS source map

The source map for JS files is controlled by sourceMap.js and accepts any source map format 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:

export default {
  output: {
    sourceMap: {
      js: 'source-map',
    },
  },
};

You can also set different source map formats based on the environment.

export default {
  output: {
    sourceMap: {
      js:
        process.env.NODE_ENV === 'production'
          ? // Use a high quality source map format for production
            'source-map'
          : // Use a more performant source map format for development
            'cheap-module-source-map',
    },
  },
};
WARNING

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.

#CSS source map

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:

export default {
  output: {
    sourceMap: {
      css: true,
    },
  },
};

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:

export default {
  output: {
    injectStyles: true,
    sourceMap: {
      css: process.env.NODE_ENV === 'development',
    },
  },
};