-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
How to import dynamic paths with Vite's new URL(url, import.meta.url)
?
#327
Comments
I am having the same problem, I have my imgs in a json to import them dynamically. if there is no solution for this, there is no way to import a folder of pictures and transform them? |
This comment was marked as off-topic.
This comment was marked as off-topic.
new URL(url, import.meta.url)
?
This comment was marked as off-topic.
This comment was marked as off-topic.
@JonasKruckenberg could you maybe look at this? Would be great, because it's pretty important feature in Vite right now. This works, and is also transformed by imagetools:
This does not:
|
Please note from the Vite docs that "the URL string must be static so it can be analyzed"
You can import a folder of pictures and transform them with |
@chojnicki this is a bug in Vite. I can reproduce this without |
I wanted to mention that I haven't found much of a use case for this feature yet. To use an example, let's assume you've got something like in the issue description:
You could also accomplish that by simply doing a relative import from the article page. You can also use If the article and image are coming from a dynamic source like a CMS then you're probably not going to be using I'd love to know if there's some use case that I'm overlooking. |
The fix for this will be in the next version of Vite: vitejs/vite#13034 |
@benmccann Thanks for handling vite issue so well. Will check that when new vite stable version will be released. About use case - it's very simple. I was using |
Closing as fixed in Vite 5 |
Hello. I'm trying to use it with latest Vite with this construction:
More about this construction
But image variable is
undefined
. What I miss? Should it works? Possible simmilar to #321The text was updated successfully, but these errors were encountered: