⚡️ Lightweight & Flexible React SVG Sprite Generator and Component for Vite, Next.js, Turbopack.
tiny-isprite v2.0 — not just a component, but a tool for generating optimized SVG sprites with color customization, CSS variables, and minification support.
- 🔹 CLI with flexible arguments
- 🎨 Supports
currentColorfor icon styling - 🖍️ Preserve multicolor icons (
--preserve-colored) - 🧩 Convert to CSS variables (
--use-css-vars) - ✂️ Minify SVG (
--minify) - ⚛️ React component for easy usage
npm install tiny-isprite- Place your
.svgicons in theicons/folder. - Run the generator:
npx build-spritenpx build-sprite ./assets/icons ./public/sprite.svg --preserve-colored --prefix custom- --minify| Argument | Description |
|---|---|
srcDir |
Directory with icons (./icons by default) |
outputFile |
Output sprite file (./public/sprite.svg) |
--preserve-colored |
Preserve multicolor icons |
--use-css-vars |
Convert fill/stroke to CSS variables |
--minify |
Minify sprite |
--prefix <prefix> |
Prefix for icon IDs |
import { Icon } from 'tiny-isprite';
<Icon name="star" size={32} className="text-blue-500" external />Generate sprite with CSS variables support:
npx build-sprite --use-css-vars:root {
--icon-fill: #4ade80;
--icon-stroke: #1e40af;
}
.custom-icon {
--icon-fill: red;
--icon-stroke: black;
}<Icon name="folder" size={48} className="custom-icon" external />➡️ Easily adapt colors to themes or component context!
Important:
For currentColor to work, the icon must inherit color from a parent element or have it defined via CSS.
- Works — when the icon is inside a parent with a Tailwind color class:
<p className="text-green-700">
Made by Dina
<Icon name="mono-heart" size={64} external />
</p>- Doesn't work — if you apply the class directly to the icon:
<Icon name="mono-heart" size={64} external className="text-red-800" />This won't change the color because the SVG <use> element doesn't directly accept Tailwind classes.
- Solution via CSS:
:root {
--all-mono-heart-fill-1: currentColor;
}<p className="text-green-700">
Made by Dina
<Icon name="mono-heart" size={64} external className="text-red-800" />
</p>In this case, the icon will take the color from the text-red-800 class.
my-app/
├── icons/ # Your raw SVG icons
├── public/
│ └── sprite.svg # Generated sprite
└── src/
- CLI arguments
- CSS Variables
- Tailwind integration example
- Watch Mode
- StackBlitz Demo
- TypeScript improvements
MIT — © 2025 Dina