Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use `rollupOptions.options.assetFileNames` when specified in the Vite config

See original GitHub issue

Typically 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) =>
                        ) {
                            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:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

ElMassimocommented, Nov 23, 2022

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 emitFile in generateBundle would 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.

lsdsjycommented, Nov 23, 2022

IIUC the api you mentioned is independent, not used by the vite plugin. I think it’s ok that we keep generatedImages as OutputAsset and just ignore the fileName property when consumed in the generateBundle hook of the vite plugin(if assetsDir is not specified).

Read more comments on GitHub >

github_iconTop 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 } = 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found