Vite plugin that imports SVG files as raw strings and optimizes them using SVGO (SVG Optimizer). Current stable version is 2.0.0, released with updated SVGO dependency. It allows custom SVGO configuration options and ships TypeScript types. Differentiates from other Vite SVG plugins by focusing solely on SVGO optimization and raw string output, without extra transformations like React components.
npm install vite-plugin-svgoVerified import paths — ran on the pinned version, not inferred.
Configures vite-plugin-svgo in vite.config.ts with SVGO options and demonstrates importing an SVG as an optimized string.
Update SVGO options to match v3 syntax (e.g., plugins array with name/params objects).
Adjust configuration to use new SVGO v3 plugin structure. Refer to SVGO migration guide.
Use SVGO v2 compatible options. Consider upgrading to v1.5.0+ for SVGO v3.
Use a different plugin (e.g., vite-plugin-svgr) if you need React components. Otherwise, use innerHTML or similar to render the string.
Add 'resolveJsonModule' and 'allowSyntheticDefaultImports' to your tsconfig compilerOptions.
Add a declaration file (e.g., svg.d.ts) with: declare module '*.svg' { const content: string; export default content; }Use ES module import syntax: import svg from 'vite-plugin-svgo'
Ensure all plugins use SVGO v3 format: { name: 'pluginName', params: {...} }. Reference SVGO v3 documentation.