['web']
>= 0.2.0
Used to set the build output type for Rsbuild.
Rsbuild supports build multiple target types for running in different target environments. After setting the correct target type, Rsbuild will optimize the build results for the environment, and enable some plugins or configs for the target environment during the build process.
By default, the targets is ['web']
, and the build result can run in a browser environment.
Rsbuild will read the Browserslist config in the project to determine the range of browsers.
Apart from 'web'
, targets
can also include the following types:
'node'
: Build for Node.js environment, usually used in SSR and other scenarios.'web-worker'
: Build for Web Worker environment.For example, to build for the Node.js environment:
When targets containing multiple values, Rsbuild will perform multiple builds at the same time.
For example, we can build a browser target and an node target at the same time:
Refers to the build target running in the Node.js environment, usually used in scenarios such as SSR.
When target
is set to 'node'
, Rsbuild will:
dist/server
directory, which can be configured via output.distPath.['node >= 16']
.If target is an array, such as building web and node targets at the same time, then the above processing will not affect the web target, The HTML, CSS and other files required for the web target will still be generated correctly.
Refers to the build target running in the Web Worker environment.
A web worker is a type of JavaScript program that runs in the background, independently of other scripts, without affecting the performance of the page. This makes it possible to run long-running scripts, such as ones that handle complex calculations or access remote resources, without blocking the user interface or other scripts. Web workers provide an easy way to run tasks in the background and improve the overall performance of web applications.
When target
is set to 'web-worker'
, Rsbuild will: