undefined
server.open
is used to configure a set of page URLs that Rsbuild will automatically open in the browser after starting the server.
You can also use the --open option of Rsbuild CLI to open the pages. When using
server.open
and--open
at the same time,--open
takes precedence.
server.open
can be set to the following values.
http://localhost:<port>
. If server.host is configured, it defaults to http://<host>:<port>
.http://localhost:<port>/home
:The port number that Rsbuild server listens on may change. For example, if the port is in use, Rsbuild will automatically increment the port number until it finds an available port.
To avoid server.open
becoming invalid due to port changes, you can use one of the following methods:
<port>
placeholder to refer to the current port number. Rsbuild will replace the placeholder with the actual port number it is listening on.Rsbuild opens pages in the system default browser by default, and also supports specifying which browser to use when starting the dev server through the BROWSER
environment variable.
Rsbuild uses the open library to open browsers, and supports opening Chrome, Edge, and Firefox:
On Windows, use cross-env to set environment variables:
You can also refer to the app option of open
to configure more special BROWSER
values, such as some OS-specific browser names:
Pass browser arguments through BROWSER_ARGS
, with multiple arguments separated by spaces:
On macOS, Rsbuild also supports opening the browser through AppleScript, which allows you to reuse existing browser tabs to open pages.
The following are the browser names supported by AppleScript:
For example:
You can set the BROWSER
environment variable in the local .env.local file, so you don't need to manually set the environment variable every time you start the dev server, and it also avoids affecting other developers in the project.
By using open.before
, you can trigger a callback function before opening the page.
When using open.before
, the page URLs can be configured via open.target
.