Skip to content

Add option for interpreting <a href="someimageurl.jpg"> as an asset #19918

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

Open
4 tasks done
jkozniewski opened this issue Apr 23, 2025 · 0 comments
Open
4 tasks done

Comments

@jkozniewski
Copy link

jkozniewski commented Apr 23, 2025

Description

The list of html tags pointing to resources that are transformed into assets by vite is listed here:
https://vite.dev/guide/features.html#html
But what if I have a following scenario when using lightbox library such as simplelightbox where the thumbnails are enclosed with tags pointing to original pictures like this:

<a href="/src/images/photos/full_res_img.jpg"> 
  <img src="/src/images/photos/thumbnail.jpg" />
</a>

The img src is transformed to point to an asset after build but the a href is not

<a href="/src/images/photos/full_res_img.jpg"> 
  <img src="assets/images/photos/thumbnail-Xycy-NDf.jpg" />
</a>

so after build it points to a file that does not exist in the bundle and that breaks the lightbox. Even without ligtbox context I can imagine is not that uncommon to use tag to point to an image directly and that just won't work properly after build.

Suggested solution

Why not add the <a> tag pointing to an file (probably excluding .html extension) to the list of transformed resources like it's the case with <img> and quite few other tags ?

If there is too high risk of breaking something maybe that could be implemented as either an optional setting in vite.config.js or on per-tag basis by adding attribute like vite-asset like this:

<a href="path/to/img.jpg" vite-asset>click to open an image</a>

alternatively using parameter appended tu the url:

<a href="path/to/img.jpg?vite_asset">click to open an image</a>

If there is some setting that I'm not aware of or any elegant solution to workaround the issue for now it would be much appreciated if someone could suggest such.

Alternative

No response

Additional context

No response

Validations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant