Skip to content

How to reference images with a dynamic path? #6

Answered by ElMassimo
mseele asked this question in Q&A
Discussion options

You must be logged in to vote

Starting in Vite 4, you can use glob imports.

Unfortunately, Vite currently does not support passing query parameters in glob imports, which would be an automatic way to generate a similar structure to the map in your example. It might be added in the future, perhaps you can suggest it as a feature request in Vite.


This plugin does provide a programmatic API that can be used directly in Vite plugins:

const image = await images.api.resolveImage('@/assets/events/${imageName}`, { preset: 'full' })

For certain use cases this is a reasonable approach, such as when using extendFrontmatter in îles.


Moving this to discussions, feel free to ask additional questions.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ElMassimo
Comment options

Answer selected by ElMassimo
Comment options

You must be logged in to vote
1 reply
@ElMassimo
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #5 on March 28, 2022 19:02.