Sets the filename of dist files.
After the production build, Rsbuild will add a hash in the middle of the filename by default. If you don't need to add it, you can set output.filenameHash to false
to disable this behavior.
The following are the details of each filename:
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.image
: The name of non-SVG images.media
: The name of media assets, such as video.To set the name of the JavaScript file to [name]_script.js
, use the following configuration:
Usually, we only set the filename hash in the production mode (i.e., when process.env.NODE_ENV === 'production'
).
If you set the filename hash in the development mode, it may cause HMR to fail (especially for CSS files). This is because every time the file content changes, the hash value changes, preventing bundler from reading the latest file content.
When you import a module via dynamic import, the module will be bundled into a single file, and its default naming rules are as follows:
dist/static/js/async/src_add_ts.js
.dist/static/js/async/798.27e3083e.js
. This is to avoid leaking the source code path in the production environment, and the number of characters is also less.If you want to specify a fixed name for the async module, you can use the magic comments provided by the bundler to achieve this, using webpackChunkName
to specify the module name:
After specifying the module name as above, the generated file will be dist/static/js/async/my-chunk-name.js
.
You can pass a function to output.filename.js
, allowing you to dynamically generate filenames based on file information:
Except for output.filename.js
, other types of files currently do not support using functions.
If you need to generate hash values on the URL query of assets, you can refer to:
In this case, the filenames of JS and CSS will not include the hash, while the URLs in the HTML will contain a hash query.