Transform your SVGs into Svelte components automatically β just by adding ?svelte to the import path!
Simple, fast, and optimized β‘οΈπ§©
npm install svelte-svg-import
# or
yarn add svelte-svg-import
# or
pnpm add svelte-svg-import
In your vite.config.js / vite.config.ts:
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { svelteSvgImportVite } from 'svelte-svg-import';
export default defineConfig({
plugins: [svelte(), svelteSvgImportVite()],
});
Now simply import SVGs like this:
<script>
import Logo from './logo.svg?svelte';
</script>
<Logo class="my-logo" />
π Done! Your SVG is now a reusable Svelte component.
Add the type declaration to your tsconfig.json:
{
"compilerOptions": {
"types": ["svelte-svg-import/type"]
}
}
π If youβre using JavaScript, make sure your editor loads the type declaration file
svelte-svg-import/typeto remove import warnings.
This plugin:
coming soonβ¦
Pull requests & issues are welcome! Letβs build cool things with Svelte together π
MIT β free for everyone