A Vite plugin that transforms SVG files into SVG sprite symbols or framework-specific components. Current stable version is 0.7.0, released with support for custom adapter types. Compatible with Vite 2–7, React 17–19, and Vue 3. Unlike svgr, this plugin generates an inline sprite and provides better render performance for large icon sets. Exports SVG as symbol IDs (vanilla), React components, or Vue components. Ships TypeScript definitions and includes SVGO optimization.
npm install vite-plugin-svg-spriteVerified import paths — ran on the pinned version, not inferred.
Configures the plugin for React, processing SVGs from src/icons, disabling removeViewBox, and using default symbol ID format.
Replace import { size } from './icon.svg' with import { attributes } from './icon.svg'.If your code relied on svg-baker exports, migrate to use this plugin's output directly.
Change const createSvgSpritePlugin = require('vite-plugin-svg-sprite') to import createSvgSpritePlugin from 'vite-plugin-svg-sprite'.Set the 'include' option to a broader micromatch pattern (e.g., '**/*.svg') to include all SVG files.
Use a default import, e.g., import createSvgSpritePlugin from 'vite-plugin-svg-sprite'.
Add one of the following to your tsconfig.json "types" array: "vite-plugin-svg-sprite/typings/vanilla", "vite-plugin-svg-sprite/typings/react", or "vite-plugin-svg-sprite/typings/vue".
Use 'import createSvgSpritePlugin from 'vite-plugin-svg-sprite'' instead of 'import { createSvgSpritePlugin } from 'vite-plugin-svg-sprite''.Use 'import { attributes } from './icon.svg'' (since v0.6.0) instead of 'import { size } from './icon.svg''.