Skip to content

Instantly share code, notes, and snippets.

@Pigamo
Last active November 7, 2024 09:16
Show Gist options
  • Save Pigamo/6ad9d769a23bbdc07a9ef6f7226cbb55 to your computer and use it in GitHub Desktop.
Save Pigamo/6ad9d769a23bbdc07a9ef6f7226cbb55 to your computer and use it in GitHub Desktop.
Imports multiple images from a folder using Vite globs
const gallery = Object.values(import.meta.glob('@assets/*.{png,jpg,jpeg,PNG,JPEG}', { eager: true, as: 'url' }))
@Pigamo
Copy link
Author

Pigamo commented Feb 24, 2023

Thanks for asking the right questions. I updated the gist to reflect the answer!

The issue is the path to the image, I've posted a question on Vite's discussion thing on GitHub . If you find or remember anything, tell me! Thank you dude

Thanks @mkxto

@PullRequestTimeout
Copy link

Does anyone know how to use this in SvelteKit?

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