Skip to content

Instantly share code, notes, and snippets.

@Pigamo
Pigamo / Vite MultiImage import
Last active November 7, 2024 09:16
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
Pigamo / Dynamic JSON Multi-Import
Created November 21, 2021 18:29
Based on StackOverflow Question, how to import multiple json files dynamically without specifically calling each one
const data = import.meta.glob('../data/*.json')
const imp = ref([{}])
// eslint-disable-next-line no-restricted-syntax
for (const path in data) {
data[path]().then((mod) => {
// const p = new URL(path, import.meta.url)
// eslint-disable-next-line no-console
console.log(path)
// imp.value.push(path)