mode
- Type:
'production' | 'development' | 'none'
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.
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.
An explicit mode takes precedence when choosing the build mode. It does not change process.env.NODE_ENV in the Node.js process.
Command line
When using the Rsbuild CLI:
rsbuildwill 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
With mode: 'development', Rsbuild uses the following defaults. You can override them in your configuration:
- When running the dev server for a web target with
dev.hmrenabled, 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
With mode: 'production', Rsbuild uses the following defaults. You can override them in your configuration:
- For web and web-worker targets, enable JavaScript code minification and register the SwcJsMinimizerRspackPlugin.
- For web and web-worker targets, enable CSS code minification and register the LightningCssMinimizerRspackPlugin.
- JavaScript and CSS filenames include hash suffixes, except JavaScript files for Node.js targets. 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 production-mode optimizations by default. Explicit configuration can still enable features such as minification.
- 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.

