CC 4.0 License
The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
Mode
- Type:
'production' | 'development' | 'none'
The mode configuration is used to set the build mode of Rspack to enable the default optimization strategy.
Default value
If mode is not specified:
- When using
@rspack/cli,rspack devandrspack servedefault to'development', andrspack builddefaults to'production'. - When using JavaScript API, the
modeoption defaults to'production'.
Usage
You can set the mode directly in Rspack config:
In actual scenarios, you can dynamically set the mode according to process.env.NODE_ENV:
Alternatively, you can set the mode using the --mode option on the Rspack CLI:
--mode option on the CLI has a higher priority than mode in Rspack config.
Optional values
mode has the following optional values:
production
In production mode, Rspack automatically enables the following optimization strategies:
- Set the default value of optimization.nodeEnv to
'production', which replacesprocess.env.NODE_ENVin code with'production'. - Set the default value of optimization.minimize to
true, and enable the default JavaScript and CSS minimizers. - Set the default value of optimization.concatenateModules to
trueto enable module concatenation (scope hoisting). - Set the default values of optimization.sideEffects, optimization.usedExports, optimization.mangleExports, and optimization.innerGraph for more aggressive tree shaking and export optimization.
- Set the default values of optimization.moduleIds and optimization.chunkIds to
'deterministic'for more stable long-term caching. - Set the default value of optimization.realContentHash to
true.
development
In development mode, Rspack automatically enables the following optimization strategies:
- Set the default value of optimization.nodeEnv to
'development', which replacesprocess.env.NODE_ENVin code with'development'. - Set the default value of devtool to
'cheap-module-source-map'for easier debugging. - Set the default value of cache to
trueto enable memory caching for faster development builds. - Set the default values of optimization.moduleIds and optimization.chunkIds to
'named'for more readable module and chunk names. - Set the default value of optimization.emitOnErrors to
true, which keeps emitting output when build fails to support local debugging.
none
When mode is set to 'none', Rspack will not enable any default optimization strategies.

