For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /config/target.md.
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.

Target

The target option describes the environment in which the output code will run. Rspack uses it to determine which platform APIs and ECMAScript syntax the target environment supports, then sets compatible defaults for module resolution conditions, externals presets, and chunk loading. The runtime code generated by Rspack also uses syntax supported by the target environment.

When their own target options are omitted, Rspack's built-in loaders and minimizers can also inherit defaults from target. However, target does not add polyfills for missing APIs.

  • Type:
type Target = false | string | string[];
  • Default: browserslist when the project includes a standard Browserslist configuration; otherwise web

Browsers

For browser applications, define the supported browsers in a shared Browserslist configuration (see Browserslist for details):

package.json
{
  "browserslist": ["fully supports es6"]
}

Use the following configuration:

rspack.config.mjs
export default {
  target: 'browserslist',
};

When the project includes a standard Browserslist configuration, target defaults to browserslist, so the explicit option can be omitted. Keeping it explicit makes the intended runtime policy clearer.

Syntax version

If you do not use Browserslist and want browser output whose runtime uses at most ES2020 syntax, combine the platform and syntax targets (see Target arrays for details):

rspack.config.mjs
export default {
  target: ['web', 'es2020'],
};

web selects the platform. es2020 limits the syntax used by the Rspack runtime; built-in transforms that inherit target also use it as their default output target.

Node.js

For a Node.js application, specify the oldest Node.js version used in deployment:

rspack.config.mjs
export default {
  target: 'node22',
};

Replace 22 with the version your application supports. A versioned target lets Rspack use runtime features known to be available in that release. An unversioned node target uses more conservative compatibility assumptions.

Web workers

For code that runs in a Web Worker, Shared Worker, or Service Worker, use:

rspack.config.mjs
export default {
  target: 'webworker',
};

This selects worker globals and chunk-loading behavior instead of browser APIs that depend on document.

Common values

In the patterns below, X and Y are version numbers, and brackets indicate optional parts. For example, node22, node22.12, and electron34-renderer are valid values; the brackets are not typed literally.

ValueUse
async-node[X[.Y]]A Node.js environment that loads chunks asynchronously with fs and vm
browserslist[:...]Infer the platform and supported features from a Browserslist configuration, environment, or inline query
electron[X[.Y]]-mainElectron main process
electron[X[.Y]]-preloadElectron preload script
electron[X[.Y]]-rendererElectron renderer process
esXLimit ECMAScript features used by the runtime; normally combined with a platform target
falseDisable target inference and target-derived defaults
node[X[.Y]]Node.js environment; chunks are loaded with require()
node-webkit[X[.Y]]Alias for the corresponding NW.js target
nwjs[X[.Y]]NW.js environment
webBrowser-like environment
webworkerWeb Worker, Shared Worker, or Service Worker environment
  • Supported ECMAScript targets are es3, es5, and es2015 through es2025.
  • An esX target describes syntax capabilities, not a runtime platform. It should usually be combined with a platform target such as web or node.
  • Versions can be specified for Node.js, Electron, and NW.js targets.

Effects

Output defaults

Rspack derives several defaults from the selected target, including:

  • module resolution conditions such as browser, node, and electron
  • output.environment, chunk format, chunk loading, worker loading, and WebAssembly loading
  • externals presets, such as keeping Node.js or Electron built-in modules external
  • platform globals and capabilities, such as document, require, global, and importScripts

These are defaults. You can override the corresponding options when the target preset does not match a specific output requirement.

Source transforms

target directly controls the syntax that Rspack may use in its generated runtime. It does not, by itself, lower the syntax of every application module.

When used without an explicit transform target, the following built-in tools inherit a compatible default from target:

Only code processed by these tools receives their transformations. Code processed by Babel follows Babel's own configuration. Built-in tools may also limit inherited targets to the versions they support.

Target arrays

A target array applies the common subset of features supported by every item to a single compilation. A typical combination adds an ECMAScript constraint to a platform target:

rspack.config.mjs
export default {
  target: ['web', 'es2018'],
};

A target array does not create a separate compilation for each environment. Combining conflicting platform targets such as ['web', 'node'] can leave defaults such as the chunk format indeterminate.

When you need separate browser and Node.js artifacts, export multiple configurations instead:

rspack.config.mjs
export default [
  {
    name: 'client',
    entry: './src/client.js',
    target: 'web',
    output: {
      filename: 'client.js',
    },
  },
  {
    name: 'server',
    entry: './src/server.js',
    target: 'node22',
    output: {
      filename: 'server.js',
    },
  },
];

Rspack runs these configurations through MultiCompiler and creates a separate compilation for each one.

Browserslist

The browserslist target uses a Browserslist query to infer both the platform and supported ECMAScript features. Browser queries select a web target, while Node.js queries select a Node.js target with matching runtime capabilities.

Rspack recognizes the following forms:

ValueResolution
browserslistUse the nearest configuration and its active environment
browserslist:modernUse the modern environment from the nearest configuration
browserslist:last 2 versionsUse an inline query and ignore the project configuration
browserslist:/path/to/configUse an explicit configuration file
browserslist:/path/to/config:modernUse the modern environment from an explicit configuration file

The nearest configuration can come from a browserslist or .browserslistrc file, or from the browserslist field in package.json. An explicitly selected browserslist target can also use the BROWSERSLIST environment variable. Rspack supports browser and Node.js queries; Electron queries are not supported.

Baseline

Rspack 2.1.9 and later support Baseline queries. For example, the following target includes browsers that support every feature in Baseline Widely Available:

rspack.config.mjs
export default {
  target: 'browserslist:baseline widely available',
};

You can also use a year query such as baseline 2024, or a fixed-date query such as baseline widely available on 2025-05-01. See Use Baseline with Browserslist for details.

Limitations

Rspack uses browserslist-rs, which does not yet implement every Browserslist feature. The following queries are currently unsupported:

  • custom usage queries, such as > 0.5% in my stats
  • coverage queries, such as cover 99.5% in my stats

Disable target

Set target to false only when you need to replace target inference with custom settings. This disables all target-derived defaults.

The following is a minimal configuration that uses the CommonJS chunk format:

rspack.config.mjs
export default {
  target: false,
  output: {
    chunkFormat: 'commonjs',
  },
};

A configuration containing only target: false will fail because Rspack cannot infer output.chunkFormat. Set output.chunkFormat explicitly, then configure other environment-dependent options, such as output.environment, chunk loading, resolution conditions, and externals presets, as needed.