Reputation: 584
I can load images dynamically from a folder in Nuxt (+ webpack) simply with a method like:
getServiceIcon(iconName) {
return require ('../../static/images/svg/services/' + iconName + '.svg');
}
I moved to Vite, and require
is not defined here (using rollup). How can I solve this, with nuxt / vite? Any idea?
Upvotes: 6
Views: 4311
Reputation: 138226
You can use import()
like this:
const getServiceIcon = async iconName => {
const module = await import(/* @vite-ignore */ `../../static/images/svg/services/${iconName}.svg`)
return module.default.replace(/^\/@fs/, '')
}
Upvotes: 9