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

rspack.config.mjs
export default {
  mode: 'production',
};

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

rspack.config.mjs
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.

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.