output.filename
- Type:
- Default:
Set the filename of output files.
After a production build, Rsbuild adds a hash to the filename by default. To disable this behavior, set output.filenameHash to false.
Rsbuild generates the final file path based on output.filename and output.distPath.
See Output files for more information.
File types
output.filename can be set differently for different file types.
Each output.filename option controls different file types:
html: The name of the HTML files.js: The name of the JavaScript files.css: The name of the CSS files.svg: The name of the SVG images.font: The name of the font files.wasm: The name of the Wasm files.image: The name of non-SVG images.media: The name of media assets, such as video.assets: The name of other static assets, such as the assets defined in Extend Asset Types.
Example
To set the name of the JavaScript files to [name]_script.js:
Set different filenames for development and production builds:
Typically, Rsbuild only sets the filename hash in production mode (process.env.NODE_ENV === 'production').
Setting the filename hash in development mode may cause HMR to fail (especially for CSS files). This happens because each time the file content changes, the hash value changes, preventing the bundler from reading the latest file content.
Filename placeholders
In output.filename, you can use filename placeholders to dynamically generate file names.
Common filename placeholders include:
[name]- chunk name for JavaScript and CSS, entry name for HTML, or the original filename without its extension for other assets.[contenthash]- hash value generated based on file content.[contenthash:<length>]- hash value generated based on file content, with specified hash length.[ext]- file extension, including the dot.
For more filename placeholders, refer to Rspack - Filename placeholders.
filename.htmlcan only use certain filename placeholders like[name]and[contenthash:<length>].filename.jsandfilename.cssdo not support[ext].
Filename of async modules
When you import a module via dynamic import, the module will be bundled into a separate file using these default naming rules:
- In development mode, the filename will be generated based on the module path, such as
dist/static/js/async/src_add_ts.js. - In production mode, filenames use short chunk IDs generated from hashes by default, such as
dist/static/js/async/a1b.27e3083eab.js. This keeps filenames short and avoids directly exposing source paths.
To specify a fixed name for the async module, use the magic comments supported by Rspack. Use rspackChunkName to specify the module name:
This sets the name part of the filename to my-chunk-name. Production builds still append a content hash by default, for example dist/static/js/async/my-chunk-name.27e3083eab.js.
Using function
You can pass a function to dynamically set the filename based on the file information.
The function receives two parameters:
pathData: An object containing file path information.assetInfo: An optional object containing additional assets information.
Dynamically set the filename for JavaScript files:
Dynamically set the filename for CSS files:
Dynamically set the filename for image files:
output.filename.html does not support using functions yet.
Query hash
To generate hash values on the URL query of assets, refer to:
In this case, the filenames of JS and CSS will not include a hash, but the URLs in the HTML will contain a hash query.

