mode
- Type:
'production' | 'development' | 'none' - Version:
>= 1.0.0
Sets the Rsbuild build mode. Each mode applies different defaults and optimizations; for example, production minifies code by default.
The Rsbuild mode value is also passed to Rspack's mode configuration.
Tip
The mode value does not change which .env file loads because .env files resolve before the Rsbuild config file.
Use the --env-mode option in the Rsbuild CLI to specify the env mode. See "Env mode" for details.
Default values
The default value of mode depends on the process.env.NODE_ENV environment variable:
- If
NODE_ENVisproduction, the default value isproduction. - If
NODE_ENVisdevelopment, the default value isdevelopment. - If
NODE_ENVhas any other value, the default value isnone.
If you set mode, the NODE_ENV value will be ignored.
rsbuild.config.ts
Command line
When using the Rsbuild CLI:
rsbuild devwill set the default values ofNODE_ENVandmodetodevelopment.rsbuild buildandrsbuild previewwill set the default values ofNODE_ENVandmodetoproduction.
JavaScript API
When using the Rsbuild JavaScript API:
- rsbuild.startDevServer and rsbuild.createDevServer will set the default values of
NODE_ENVandmodetodevelopment. - rsbuild.build and rsbuild.preview will set the default values of
NODE_ENVandmodetoproduction.
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_ENVin the source code will be replaced with'development'. - The
import.meta.env.MODEin the source code will be replaced with'development'. - The
import.meta.env.DEVin the source code will be replaced withtrue. - The
import.meta.env.PRODin the source code will be replaced withfalse. - 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.
- JavaScript and CSS filenames include hash suffixes. See output.filenameHash.
- CSS Modules class names are shorter. See cssModules.localIdentName.
- JavaScript and CSS source maps are disabled. See output.sourceMap.
- The
process.env.NODE_ENVin the source code will be replaced with'production'. - The
import.meta.env.MODEin the source code will be replaced with'production'. - The
import.meta.env.DEVin the source code will be replaced withfalse. - The
import.meta.env.PRODin the source code will be replaced withtrue. - 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_ENVin the source code will not be replaced. - The
import.meta.env.MODEin the source code will be replaced with'none'. - The
import.meta.env.DEVin the source code will be replaced withfalse. - The
import.meta.env.PRODin the source code will be replaced withfalse. - Use output.assetPrefix as the URL prefix for static assets.

