Back to Rspack

Mode

website/docs/en/config/mode.mdx

2.0.13.6 KB
Original Source

import WebpackLicense from '@components/WebpackLicense'; import PropertyType from '@components/PropertyType';

<WebpackLicense from="https://webpack.js.org/configuration/mode/" />

Mode

<PropertyType 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 dev and rspack serve default to 'development', and rspack build defaults to 'production'.
  • When using JavaScript API, the mode option defaults to 'production'.

Usage

You can set the mode directly in Rspack config:

js
export default {
  mode: 'production',
};

In actual scenarios, you can dynamically set the mode according to process.env.NODE_ENV:

js
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:

bash
rspack --mode=production

:::info --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:

development

In development mode, Rspack automatically enables the following optimization strategies:

  • Set the default value of optimization.nodeEnv to 'development', which replaces process.env.NODE_ENV in code with 'development'.
  • Set the default value of devtool to 'cheap-module-source-map' for easier debugging.
  • Set the default value of cache to true to 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.