website/docs/en/config/mode.mdx
import WebpackLicense from '@components/WebpackLicense'; import PropertyType from '@components/PropertyType';
<WebpackLicense from="https://webpack.js.org/configuration/mode/" />The mode configuration is used to set the build mode of Rspack to enable the default optimization strategy.
If mode is not specified:
@rspack/cli, rspack dev and rspack serve default to 'development', and rspack build defaults to 'production'.mode option defaults to 'production'.You can set the mode directly in Rspack config:
export default {
mode: 'production',
};
In actual scenarios, you can dynamically set the mode according to process.env.NODE_ENV:
const isProduction = process.env.NODE_ENV === 'production';
export default {
mode: isProduction ? 'production' : 'development',
};
Alternatively, you can set the mode using the --mode option on the Rspack CLI:
rspack --mode=production
:::info
--mode option on the CLI has a higher priority than mode in Rspack config.
:::
mode has the following optional values:
In production mode, Rspack automatically enables the following optimization strategies:
'production', which replaces process.env.NODE_ENV in code with 'production'.true, and enable the default JavaScript and CSS minimizers.true to enable module concatenation (scope hoisting).'deterministic' for more stable long-term caching.true.In development mode, Rspack automatically enables the following optimization strategies:
'development', which replaces process.env.NODE_ENV in code with 'development'.'cheap-module-source-map' for easier debugging.true to enable memory caching for faster development builds.'named' for more readable module and chunk names.true, which keeps emitting output when build fails to support local debugging.When mode is set to 'none', Rspack will not enable any default optimization strategies.