Home > @lynx-js/rspeedy > Config > mode
Config.mode property
Specify the build mode for Rsbuild and Rspack, as each mode has different default behavior and optimizations.
Signature:
Remarks
The default value of mode depends on the process.env.NODE_ENV environment variable:
-
If
NODE_ENVis production, the default value is production. -
If
NODE_ENVis development, the default value is development. -
If
NODE_ENVhas any other value, the default value is none. -
If you set the value of mode, the value of
NODE_ENVwill be ignored.
When using Rspeedy's CLI:
-
rspeedy devandrspeedy previewwill set the default values ofNODE_ENVandmodeto'development'. -
rspeedy buildwill set the default values ofNODE_ENVandmodeto'production'.
Example 1
If the value of 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.
Example 2
If the value of mode is 'production':
-
Enable JavaScript code minification and register the SwcJsMinimizerRspackPlugin.
-
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_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.