> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

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

```js title="rspack.config.mjs"
export default {
  mode: 'production',
};
```

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

```js title="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:

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

- Set the default value of [optimization.nodeEnv](/config/optimization.md#optimizationnodeenv) to `'production'`, which replaces `process.env.NODE_ENV` in code with `'production'`.
- Set the default value of [optimization.minimize](/config/optimization.md#optimizationminimize) to `true`, and enable the default JavaScript and CSS minimizers.
- Set the default value of [optimization.concatenateModules](/config/optimization.md#optimizationconcatenatemodules) to `true` to enable module concatenation (scope hoisting).
- Set the default values of [optimization.sideEffects](/config/optimization.md#optimizationsideeffects), [optimization.usedExports](/config/optimization.md#optimizationusedexports), [optimization.mangleExports](/config/optimization.md#optimizationmangleexports), and [optimization.innerGraph](/config/optimization.md#optimizationinnergraph) for more aggressive tree shaking and export optimization.
- Set the default values of [optimization.moduleIds](/config/optimization.md#optimizationmoduleids) and [optimization.chunkIds](/config/optimization.md#optimizationchunkids) to `'deterministic'` for more stable long-term caching.
- Set the default value of [optimization.realContentHash](/config/optimization.md#optimizationrealcontenthash) to `true`.

### development

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

- Set the default value of [optimization.nodeEnv](/config/optimization.md#optimizationnodeenv) to `'development'`, which replaces `process.env.NODE_ENV` in code with `'development'`.
- Set the default value of [devtool](/config/devtool.md) to `'cheap-module-source-map'` for easier debugging.
- Set the default value of [cache](/config/cache.md) to `true` to enable memory caching for faster development builds.
- Set the default values of [optimization.moduleIds](/config/optimization.md#optimizationmoduleids) and [optimization.chunkIds](/config/optimization.md#optimizationchunkids) to `'named'` for more readable module and chunk names.
- Set the default value of [optimization.emitOnErrors](/config/optimization.md#optimizationemitonerrors) 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.


This page is adapted from [webpack documentation](https://webpack.js.org/configuration/mode/) under the [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), with modifications.

