Skip to content

Instantly share code, notes, and snippets.

@bluwy
Created May 4, 2021 15:52
Show Gist options
  • Select an option

  • Save bluwy/7fd074652a9e107d76f534a714dda7de to your computer and use it in GitHub Desktop.

Select an option

Save bluwy/7fd074652a9e107d76f534a714dda7de to your computer and use it in GitHub Desktop.
Import SVG as Svelte component
import fs from 'fs/promises'
import { defineConfig } from 'vite'
import svelte from '@sveltejs/vite-plugin-svelte'
export default defineConfig({
plugins: [svelteSvgPlugin(), svelte({ extensions: ['.svelte', '.svg'] })],
})
function svelteSvgPlugin() {
return {
name: 'svelte-svg',
enforce: 'pre',
load(id) {
if (id.endsWith('.svg')) {
return fs.readFile(id, 'utf-8')
}
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment