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
Used to configure the target environment of Rspack output and the ECMAScript version of Rspack runtime code.
- Type:
string | string[] - Default:
browserslistif the current project has a browserslist config, otherwiseweb.
string
The following options are now supported:
The esX in the target configuration can only specify the ECMAScript version of the Rspack runtime code. If you want to specify the ECMAScript version of the user code, you can use builtin:swc-loader or babel-loader to degrade the user code.
Example
Specify that the Compiler needs to compile to the Node.js environment:
When multiple targets are passed, then common subset of features will be used:
Note that not all targets may be mixed for now. When specifying that the Compiler needs to be compiled for multiple platforms, an error is reported:
For this case, you can define multiple Rspack configurations for bundling based on MultiCompiler.
browserslist
If the current project has a browserslist config, then Rspack will use it for:
- Determinate ES-features that may be used to generate the Rspack runtime code (this will not affect the transpilation result of user code).
- Infer a target environment (e.g:
last 2 node versionsthe same astarget: "node"with someoutput.environmentsettings).
Browserslist can specify which browsers your web application can run in, it provides a configuration for specifying browsers range. Browserslist has become a standard in the industry, it is used by libraries such as Autoprefixer, Babel, ESLint, PostCSS, SWC and webpack.
Supported browserslist values:
browserslist- use automatically resolved browserslist config and environment (from the nearest.browserslistrcfile,package.json'sbrowserslistfield, orBROWSERSLISTenvironment variable, see browserslist documentation for details)browserslist:modern- usemodernenvironment from automatically resolved browserslist configbrowserslist:last 2 versions- use an explicit browserslist query (config will be ignored)browserslist:/path/to/config- explicitly specify browserslist configbrowserslist:/path/to/config:modern- explicitly specify browserslist config and an environment
Node.js version
A version of node or electron may be optionally specified. This is denoted by the [[X].Y] in the table above.
When Rspack generates runtime code, this helps determine which ES features can be used (all chunks and modules are wrapped by runtime code).
target: false
If none of the predefined targets in the above list meet your needs, you can set target to false, which will instruct Rspack not to use any plugins.

