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 Pageroot
Next Pageplugins

#mode

  • Type: 'production' | 'development' | 'none'
  • Version: >= 1.0.0

Specify the build mode for Rsbuild, as each mode has different default behavior and optimizations. For example, the production mode will minify code by default.

The value of Rsbuild mode is also be passed to the mode configuration of Rspack.

TIP

The value of mode does not affect the loading results of the .env file, as the .env file is resolved before the Rsbuild configuration file.

Rsbuild CLI supports using the --env-mode option to specify the env mode. See "Env mode" for more details.

#Default values

The default value of mode depends on the process.env.NODE_ENV environment variable:

  • If NODE_ENV is production, the default value is production.
  • If NODE_ENV is development, the default value is development.
  • If NODE_ENV has any other value, the default value is none.

If you set mode, the NODE_ENV value will be ignored.

rsbuild.config.ts
export default {
  mode: 'production',
};

#Command line

When using Rsbuild's command line:

  • rsbuild dev will set the default values of NODE_ENV and mode to development.
  • rsbuild build and rsbuild preview will set the default values of NODE_ENV and mode to production.

#JavaScript API

When using Rsbuild's JavaScript API:

  • rsbuild.startDevServer and rsbuild.createDevServer will set the default values of NODE_ENV and mode to development.
  • rsbuild.build and rsbuild.preview will set the default values of NODE_ENV and mode to production.

#Development mode

If mode is development:

  • Enable HMR and register the HotModuleReplacementPlugin.
  • Generate JavaScript source maps, but do not generate CSS source maps. See output.sourceMap for details.
  • The process.env.NODE_ENV in the source code will be replaced with 'development'.
  • The import.meta.env.MODE in the source code will be replaced with 'development'.
  • The import.meta.env.DEV in the source code will be replaced with true.
  • The import.meta.env.PROD in the source code will be replaced with false.
  • Use dev.assetPrefix as the URL prefix for static assets.

#Production mode

If mode is production:

  • Enable JavaScript code minification and register the SwcJsMinimizerRspackPlugin.
  • Enable CSS code minification and register the LightningCssMinimizerRspackPlugin.
  • Generated JavaScript and CSS filenames will have hash suffixes, see output.filenameHash.
  • Generated CSS Modules classnames will be shorter, see cssModules.localIdentName.
  • Do not generate JavaScript and CSS source maps, see output.sourceMap.
  • The process.env.NODE_ENV in the source code will be replaced with 'production'.
  • The import.meta.env.MODE in the source code will be replaced with 'production'.
  • The import.meta.env.DEV in the source code will be replaced with false.
  • The import.meta.env.PROD in the source code will be replaced with true.
  • Use output.assetPrefix as the URL prefix for static assets.

#None mode

If mode is none:

  • Do not enable any optimizations.
  • The process.env.NODE_ENV in the source code will not be replaced.
  • The import.meta.env.MODE in the source code will be replaced with 'none'.
  • The import.meta.env.DEV in the source code will be replaced with false.
  • The import.meta.env.PROD in the source code will be replaced with false.
  • Use output.assetPrefix as the URL prefix for static assets.