This section describes some dev configurations in Rsbuild.
boolean | string
'/'
Set the URL prefix of static assets in the development environment.
assetPrefix
will affect the URLs of most of the static assets, including JavaScript files, CSS files, images, videos, etc. If an incorrect value is specified, you'll receive 404 errors while loading these resources.
This config is only used in the development environment. In the production environment, please use the output.assetPrefix
to set the URL prefix.
If assetPrefix
is set to true
, the URL prefix will be http://localhost:port/
:
The script URL will be:
If assetPrefix
is set to false
or not set, /
is used as the default value.
When the value of assetPrefix
is string
type, the string will be used as the URL prefix:
The script URL will be:
dev.assetPrefix
corresponds to the following native configurations:
The differences from the native configuration are as follows:
dev.assetPrefix
only takes effect in the development environment.dev.assetPrefix
automatically appends a trailing /
by default.dev.assetPrefix
is written to the process.env.ASSET_PREFIX
environment variable.() => Promise<void> | void
undefined
dev.beforeStartUrl
is used to execute a callback function before opening the startUrl
, this config needs to be used together with dev.startUrl
.
The config of HMR client, which are usually used to set the WebSocket URL of HMR.
boolean
true
Whether to enable gzip compression for served static assets.
If you want to disable the gzip compression, you can set compress
to false
:
The config of devMiddleware. Current options is the subset of webpack-dev-middleware.
Record<string, string>
undefined
Adds headers to all responses.
boolean | ConnectHistoryApiFallbackOptions
false
The index.html page will likely have to be served in place of any 404 responses. Enable dev.historyApiFallback
by setting it to true
:
For example, if you use client-side routing and want all page requests to fallback to index.html, you can configure it as follows:
For more options and information, see the connect-history-api-fallback documentation.
boolean
true
Whether to enable Hot Module Replacement.
If hmr
is set to false
, the HMR and react-refresh will no longer work.
string
0.0.0.0
Specify the host that the dev server listens to.
By default, the dev server will listen to 0.0.0.0
, which means listening to all network interfaces, including localhost
and public network addresses.
If you want the dev server to listen only on localhost
, you can set it to:
boolean | { key: string; cert: string }
false
After configuring this option, you can enable HTTPS Dev Server, and disabling the HTTP Dev Server.
HTTP:
HTTPS:
You can directly set https
to true
, Rsbuild will automatically generate the HTTPS certificate based on devcert.
When using this method, you need to manually install the devcert dependency in your project:
Then configure dev.https
to true
:
The devcert has some limitations, it does not currently support IP addresses yet.
The https proxy automatically installs the certificate and needs root authority, please enter the password according to the prompt.The password is only used to trust the certificate, and will not be leaked or be used elsewhere.
You can also manually pass in the certificate and the private key required in the dev.https
option. This parameter will be directly passed to the createServer method of the https module in Node.js.
For details, please refer to https.createServer.
number
8080
Specify a port number for Dev Server to listen.
By default, Dev Server listens on port 8080
and automatically increments the port number when the port is occupied.
Set the port to 3000
:
process.env.NODE_ENV === 'production'
Whether to display progress bar during compilation.
By default, Rsbuild only enables the progress bar when production building.
id
If you need to modify the text displayed on the left side of the progress bar, you can set the id
option:
Record<string, string> | Record<string, ProxyDetail>
undefined
Proxying some URLs.
A request to /api/users will now proxy the request to http://localhost:3000/api/users.
If you don't want /api to be passed along, we need to rewrite the path:
The DevServer Proxy makes use of the http-proxy-middleware package. Check out its documentation for more advanced usages.
The full type definition of DevServer Proxy is:
In addition to the http-proxy-middleware option, we also support the bypass and context configuration:
null
or undefined
to continue processing the request with proxy.false
to produce a 404 error for the request.undefined
Provides the ability to execute a custom function and apply custom middlewares.
The order among several different types of middleware is: unshift
=> internal middlewares => push
.
It is possible to use some server api to meet special scenario requirements:
boolean | string | string[] | undefined
undefined
dev.startUrl
is used to set the URL of the page that automatically opens in the browser when Dev Server starts.
By default, no page will be opened.
You can set it to the following values:
Since the port number may change, you can use the <port>
placeholder to refer to the current port number, and Rsbuild will automatically replace the placeholder with the actual listening port number.
On MacOS, you can open the specified browser when Dev Server starts, by set environment variable BROWSER
, support values: