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'
  • Default:'production'

The mode configuration is used to set the build mode of Rspack to enable the default optimization strategy.

Usage

You can set the mode directly in rspack.config.js:

rspack.config.js
module.exports = {
  mode: 'production',
};

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

rspack.config.js
const isProduction = process.env.NODE_ENV === 'production';

module.exports = {
  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.js.

Optional Values

mode has the following optional values:

production

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

  • Replace process.env.NODE_ENV in code with 'production'.
  • Set the default value of optimization.minimize to true to enable SWC minification.

development

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

  • Replace process.env.NODE_ENV in code with 'development'.
  • Set proper naming format for modules and chunks.

none

When mode is set to 'none', Rspack will not enable any default optimization strategies.