Vite 4.x plugin (v2.3.0) to import SVG files as Svelte components, with optional SVGO optimization. It requires the `?component` suffix (or `?c`) to distinguish SVG components from plain SVG URLs, but this can be disabled via `requireSuffix: false`. The plugin is Svelte 3/4 compatible but does NOT support Svelte 5 or Vite 5. It ships TypeScript types. Releases are infrequent, with v2 being the current stable line. Alternatives include `svelte-svg` or manual import via `{@html}`.
npm install vite-plugin-svelte-svgVerified import paths — ran on the pinned version, not inferred.
Configures Vite with svelte-svg plugin and usage: imports an SVG as a Svelte component with the ?component suffix.
Downgrade to Vite 4.x or Svelte 4.x, or use an alternative plugin like 'vite-plugin-svelte-svg2' which supports Vite 5.
Set `requireSuffix: false` in plugin options to import SVG without suffix, but note that this may conflict with other SVG handling.
Add a declaration file `src/svg.d.ts` with: declare module '*.svg?component' { import type { SvelteComponent } from 'svelte'; export default class extends SvelteComponent {} } or use `vite-plugin-svelte-svg/types`.Add `{ name: 'removeViewBox', active: false }` to `svgoConfig.plugins`.Restart dev server after modifying SVG files.
Run `npm install -D vite-plugin-svelte-svg` and ensure your vite.config.js uses `import` syntax.
Add `import svelteSVG from 'vite-plugin-svelte-svg'` to vite.config.js and include it in the plugins array.
Use `import MyIcon from 'path/icon.svg?component'` with the suffix.
Set `svgoConfig: { plugins: [{ name: 'removeViewBox', active: false }] }`.