SVG Sprite Plugin Vite is a lightweight Vite plugin that automatically collects all SVG files from a specified directory, combines them into a single SVG sprite, and injects it directly into your HTML. It supports Hot Module Replacement (HMR) during development and ensures seamless integration with modern frameworks like Vue, React, or plain HTML projects.
Features
🌟 Automatic SVG Sprite Generation: Combines all SVG files into a single sprite using <symbol> tags.
🔧 HTML Injection: The generated sprite is automatically injected into the <body> of your application.
🔥 Hot Module Replacement (HMR): Automatically updates the sprite when SVG files change during development.
🛠️ Customizable: Configure the source directory for SVG files and XML namespace (xmlns).
Installation
Install the plugin via npm:
1npm install svg-sprite-plugin-vite
1yarn add svg-sprite-plugin-vite
Configure the Plugin in vite.config.ts
Add the plugin to your Vite configuration: