Used to configure the target environment of Rspack output and the ECMAScript version of Rspack runtime code.

  • Type: string | string[]


The following options are now supported:

options description
'node[[X].Y]' Compile as available for Node.js environments
'async-node[[X].Y]' Compile for usage in a Node.js-like environment (uses fs and vm to load chunks asynchronously)
'web' Compile as available in the browser environment (default)
'esX' Compile Rspack runtime to the corresponding ECMAScript version. Currently supports es3, es5, es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022 (es5 is used by default)
'browserslist' Infer the ECMAScript version based on the configured browserslist
'electron[[X].Y]-main' Compile for Electron for main process.
'electron[[X].Y]-renderer' Compile for Electron for renderer process, providing a target using array-push as chunkFormat and jsonp as chunkLoading for browser environments and NodeTargetPlugin and ExternalsPlugin for CommonJS and Electron built-in modules.
'electron[[X].Y]-preload' Compile for Electron for preload script of renderer process
Specifies the ECMAScript version of the user code

The esX in the target configuration can only specify the ECMAScript version syntax of the code in the Rspack runtime. If you want to specify the ECMAScript version of the user code, you should use builtin:swc-loader, or babel-loader, or swc-loader to degrade the user code.


Specify that the Compiler needs to compile to the Node.js environment:

module.exports = {
  target: 'node',

When specifying that the Compiler needs to be compiled for multiple platforms, an error is reported:

module.exports = {
  target: ['web', 'node'],