dev.assetPrefix
- Type:
boolean | string | 'auto' - Default: server.base
Set the URL prefix of static assets in development mode.
assetPrefix affects most static asset URLs, including JavaScript files, CSS files, images, videos, etc. If it is set incorrectly, these resources may return 404 errors.
This config is only used in development mode. In production mode or none mode, use output.assetPrefix to configure the URL prefix.
Default value
The default value of dev.assetPrefix is the same as server.base.
When server.base is /foo, index.html and other static assets can be accessed through http://localhost:3000/foo/.
When you customize dev.assetPrefix, keep its URL prefix consistent with server.base so assets stay accessible through the Rsbuild dev server. For example:
Boolean type
If assetPrefix is set to true, the URL prefix will be http://localhost:<port>/:
The resource URL loaded in the browser is as follows:
If assetPrefix is set to false or not set, / is used as the default value.
String type
When the value of assetPrefix is a string type, the string will be used as a prefix and automatically appended to the static resource URL.
- For example, set to a path relative to the root directory:
The resource URL loaded in the browser is as follows:
- For example, set to a complete URL:
The resource URL loaded in the browser is as follows:
Port placeholder
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 dev.assetPrefix becoming invalid due to port changes, you can use one of the following methods:
- Enable server.strictPort.
- Use the
<port>placeholder to refer to the current port number. Rsbuild will replace the placeholder with the actual port number it is listening on.
Path types
The assetPrefix option accepts the following path types:
- absolute path: The most common choice, including specific server paths like
/assets/. - 'auto': Rspack will automatically calculate the path and generate relative paths based on file location.
It's not recommended to set assetPrefix as a relative path, such as './assets/'. This is because when assets are at different path depths, using relative paths may cause assets to load incorrectly.
Compare with publicPath
The functionality of dev.assetPrefix is basically the same as the output.publicPath config in Rspack.
The differences from the native configuration are as follows:
dev.assetPrefixonly takes effect in development mode.dev.assetPrefixdefault value is the same as server.base.dev.assetPrefixautomatically appends a trailing/by default.- The value of
dev.assetPrefixis written to the process.env.ASSET_PREFIX environment variable (can only be accessed in client code).
Dynamic asset prefix
Use the __webpack_public_path__ variable provided by Rspack to dynamically set the URL prefix of static assets in JavaScript code.

