import.meta.glob not working in production #15564
Unanswered
Chris-Is-Awesome
asked this question in
Q&A
Replies: 1 comment
-
Found the source of the problem, though don't have an ideal fix for it. The filenames change because of asset hashing, which is something Vite does automatically. You can disable it in the build: {
rollupOptions: {
output: {
assetFileNames: `assets/[name].[ext]`
}
}
} This will keep the names as they are in source, but I think it would cause problems if you have files with the same filename, as hashing prevents that from happening in dist. More info on this workaround: Issue #378 I still would like a way to dynamically import the hashed images, but this is a workaround. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am importing all images in a directory like so
import.meta.glob("../assets/images/item wheel/*"
(images are insrc
directory, as I've read dynamic imports can't be done frompublic
.It works fine in dev but not in production. I'm not sure of another way to handle dynamic multi imports, so if there is a better way, please let me know!
Edit: I found part of the problem. When built, the image path changes. Goes from
src/assets/images/item wheel/clawshot.webp
toassets/clawshot-I1HS8CSe.webp
in dist folder. Is there a reason for the filename changing and the folder not persisting? Seems like I'll have to change the relative path based on if it's dev or production which doesn't seem practical...Beta Was this translation helpful? Give feedback.
All reactions