Use `rollupOptions.options.assetFileNames` when specified in the Vite config
See original GitHub issueTypically in vite we use build.rollupOptions.output.assetFileNames to tweak output directory and file names, like:
rollupOptions: {
output: {
assetFileNames: (asset) => {
if (
['.jpg', '.png', '.svg', '.avif', '.webp'].some((ext) =>
asset.name?.endsWith(ext),
)
) {
return 'images/[name]-[hash][extname]';
}
return 'assets/[name]-[hash][extname]'; // for other assets like fonts and audios etc.
},
},
While this plugin provides an assetsDir option, it should still conform to the idiom above when assetsDir is not specified. But unfortunately that’s not the current behavior.
I can submit a PR for this if feasible.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Build Options
Directly customize the underlying Rollup bundle. This is the same as options that can be exported from a Rollup config file and will...
Read more >output.assetFileNames does not work when the project use ...
Describe the bug When the project use vite@2.5.0-beta.3 and @vitejs/plugin-legacy, ... const { rollupOptions } = config.build const { output } ...
Read more >Vite Configuration
The following is intended to provide coverage for general expectations using Adobe's AEM Archetype as a reference. Recommended configuration #.
Read more >javascript - Vite - change ouput directory of assets
The output filenames are configured in Rollup with build.rollupOptions : Set output.assetFileNames to configure the asset filenames (for ...
Read more >Configuring Astro - Astro Documentation
A valid Astro config file exports its configuration using the default export, ... export default defineConfig({ // your configuration options here.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
One of the things that makes this plugin complex is that you need the resolved asset URLs as a string in JS, so that they can be injected into HTML as-is.
Using
emitFileingenerateBundlewould force you to do a second pass replacing any strings that reference the assets, to replace the original filename with the fingerprinted version.Feel free to submit a PR if you find a way to make it work, but I don’t think it a small feature like
assets/image-[name][hash][extname]justifies a large change to the architecture of the plugin.IIUC the api you mentioned is independent, not used by the vite plugin. I think it’s ok that we keep
generatedImagesasOutputAssetand just ignore thefileNameproperty when consumed in thegenerateBundlehook of the vite plugin(ifassetsDiris not specified).