Vite SVG Loader is a Vite plugin designed to seamlessly load SVG files as Vue 3 components within a Vite project. It automatically optimizes SVGs using SVGO, which can be configured or entirely disabled on a per-file or global basis. The package is currently stable at version 5.1.1 and receives active maintenance, including compatibility updates for new Vite and Vue versions, as well as security patches for its dependencies. Its release cadence is moderate, with several updates per year, indicating ongoing development. Key differentiators include its flexible import options, allowing SVGs to be loaded as Vue components (default), raw strings (`?raw`), or URL data (`?url`), and the ability to skip SVGO for specific files (`?skipsvgo`). This provides developers with granular control over how SVG assets are handled in their Vue applications.
npm install vite-svg-loaderVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure `vite-svg-loader` in `vite.config.ts`, including SVGO customization, and how to import SVGs as both Vue components and URLs in a Vue SFC.
Upgrade `vite-svg-loader` to version 5.0.0 or later: `npm install vite-svg-loader@latest` or `yarn add vite-svg-loader@latest`.
Review your `svgoConfig` options against SVGO v3 documentation if you encounter unexpected SVG output or build errors after upgrading to `vite-svg-loader@4.0.0`.
Ensure you are using `vite-svg-loader` version 5.1.0 or newer to avoid potential CommonJS compatibility issues related to package type changes. Prefer ESM `import` statements.
Immediately upgrade `vite-svg-loader` to version 5.1.1 or higher to patch the high-severity vulnerability: `npm update vite-svg-loader` or `yarn upgrade vite-svg-loader`.
Add `/// <reference types="vite-svg-loader" />` to your `vite-env.d.ts` file or other global declaration file.
Add `/// <reference types="vite-svg-loader" />` to your `vite-env.d.ts` file.
Run `npm install --save-dev vite-svg-loader` (or `yarn add -D vite-svg-loader`) and ensure `svgLoader()` is included in `plugins: []` in your `vite.config.js/ts`.
Review your `svgoConfig` in `vite.config.js/ts` and ensure it adheres to the SVGO v3 configuration format. You can also temporarily set `svgo: false` to isolate if the problem is with SVGO configuration.