Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using [hash] as directory in rollup assetFileNames incompatible with astro:assets #8739

Closed
1 task
reupen opened this issue Oct 3, 2023 · 2 comments · Fixed by #10567
Closed
1 task

Using [hash] as directory in rollup assetFileNames incompatible with astro:assets #8739

reupen opened this issue Oct 3, 2023 · 2 comments · Fixed by #10567
Assignees
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope)

Comments

@reupen
Copy link

reupen commented Oct 3, 2023

Astro Info

Astro                    v3.2.2
Node                     v18.18.0
System                   Windows (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

n/a

Describe the Bug

Configuring vite.build.rollupOptions.output.assetFileNames to something like 'assets/[hash]/[name][extname]' and using Image from astro:assets results in an error during production builds.

An example error is:

 generating optimized images 
 error   ENOENT: no such file or directory, open 'F:\Web\astro-repros\dist\assets\red-square.png'

Configuring build.assets doesn't help here (as [hash] is missing from the path, and you can't add it in using build.assets).

Note:

  • there is no problem when using a plain <img> element
  • there is no problem when using the dev server
  • this wasn't failing with Astro 2.x and @astrojs/image (though it didn't respect assetFileNames for the converted images)

The repro is on GitHub as StackBlitz seems to hang during generating optimized images.

What's the expected result?

This should work, preferably automatically, but failing that with further manual configuration.

Link to Minimal Reproducible Example

https://github.com/reupen/astro-repros

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Oct 3, 2023
@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope) and removed needs triage Issue needs to be triaged labels Oct 3, 2023
@pateljoel
Copy link

Can confirm that this is happening for me as well.

@u3u
Copy link

u3u commented Dec 3, 2023

I use the tailwind integration, there is only one global CSS file, but I found that its file name is about.[hash].css, so I want to customize the CSS file name through vite.build.rollupOptions.output.assetFileNames, but when I set it, a build error occurs.

rollupOptions: {
  output: {
    assetFileNames: (chunkInfo) => {
      if (chunkInfo.name?.endsWith('.css')) return 'assets/tailwind.[hash].css';

      return 'assets/[name].[hash][extname]';
    },
  },
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: assets Related to the Assets feature (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants