Skip to content

Instantly share code, notes, and snippets.

@mkxto
Created February 24, 2023 17:47
Show Gist options
  • Save mkxto/e3068368b7326dd4124f77e0a4f53d66 to your computer and use it in GitHub Desktop.
Save mkxto/e3068368b7326dd4124f77e0a4f53d66 to your computer and use it in GitHub Desktop.
Import all image from a folder with Vite, this version work in both dev and "release" mode.
Object.values(import.meta.glob('../path/*.{png,jpg,jpeg,PNG,JPEG}', { eager: true, as: 'url' }))
/*
Example:
[
0: "/src/assets/asso/Nogent_Seine.jpeg"
1: "/src/assets/asso/NogentsurSeine(2).jpeg"
2: "/src/assets/asso/Rimaucourt(2).jpg"
3: "/src/assets/asso/Rimaucourt(3).jpg"
4: "/src/assets/asso/Rimaucourt(4).jpg"
5: "/src/assets/asso/Rimaucourt.jpg"
6: "/src/assets/asso/Thaon_Vosges.jpg"
7: "/src/assets/asso/ThaonlesVosges(2).jpg"
8: "/src/assets/asso/ThaonlesVosges(3).jpg"
9: "/src/assets/asso/ThaonlesVosges(4).jpg"
10: "/src/assets/asso/ThaonlesVosges(5).jpg"
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment