A Vite plugin that imports SVG files as React components using SVGR, with zero-config defaults and full configurability. v1.0.1 is the current stable version, with slow release cadence. It automatically transforms all SVG imports to React components without needing a query string like ?component, different from other SVGR Vite plugins. Ships TypeScript types, uses SVGO for optimization, and supports micromatch patterns to filter which SVGs are transformed. Requires peer dependencies: react >= 17.0.2 and vite >= 2.7.13.
npm install vite-plugin-svgr-componentVerified import paths — ran on the pinned version, not inferred.
Configures the plugin in vite.config.ts with default options, then imports an SVG as a React component and uses it with optional title and titleId props.
Use import syntax instead of require().
If you need the raw SVG URL or file content, use a different import approach (e.g., ?url or ?raw).
Add /// <reference types="vite-plugin-svgr-component/client" /> to your vite-env.d.ts file.
Use importStringPattern to restrict which files are transformed (best practice).
Test SVGR option combinations; refer to SVGR documentation.
Change to import { svgrComponent } from 'vite-plugin-svgr-component'Use import Icon from './icon.svg' (default import).
Use /// <reference types="vite-plugin-svgr-component/client" /> in a .d.ts file.
Add the triple-slash reference directive mentioned above.