Open kamil-hammouche opened 3 years ago
Duplicate of #86
In Nuxt 3, you don't need svg-module
, but can instead create a custom component utilizing Vite's glob import:
<template>
<span v-if="icon" class="h-[1em] w-[1em]" v-html="icon" />
</template>
<script setup lang="ts">
const props = defineProps<{
name?: string
}>()
// Auto-load icons
const icons = Object.fromEntries(
Object.entries(import.meta.glob('~/assets/images/*.svg', { as: 'raw' })).map(
([key, value]) => {
const filename = key.split('/').pop()!.split('.').shift()
return [filename, value]
},
),
)
// Lazily load the icon
const icon = props.name && (await icons?.[props.name]?.())
</script>
Hello,
I can't manage to load SVG using
@nuxtjs/svg
. I've added properly the build module in thenuxt.config.js
file and they still don't load. I've seen some dev complaining that this might be due to ViteJS, so I aswell added thevite-svg-loader
dependency but I have this error:__vite_ssr_import_0__.createElementVNode is not a function
Here's my
nuxt.config.js
fileAnd here's how I load my SVGs :
Icon.vue
Usage :
Best regards,