Skip to content

@sv/svg-sprites

Compiles svgs in a directory to a spritesheet and make it available as text or blob.

Includes a CustomElement that makes it easy to use any icon.

<svg-icon icon="speaker" />

Or SSR the SVG symbols into the page, for use with <use href="..."/> tags.

---
import { svg } from 'svg-sprites/sheet';
---
<div class="hidden" set:html={await svg()}></div>

Installation

Make sure your project is set up with access to the registry as described in Setup.

Terminal window
pnpm add @sv/svg-sprites

Usage

Vite configuration

import svgSprite from "svg-sprites/vite";
export default {
plugins: [
svgSprite({ dir: ["assets/icons/*.svg"] }),
],
};

Next / Webpack configuration

/** @type {import('next').NextConfig} */
module.exports = {
webpack(config, options) {
config.module.rules.push({
use: [
{
loader: "svg-sprites/loader",
options: {
dir: "./assets/icons/*.svg",
},
},
],
});
return config;
},
};

Component Usage

import "svg-sprites/svg-icon";
<body>
<svg-icon icon="speaker" />
</body>

Changelog


Fixes

  • Optimize svg icon component

0.5.1 (2025-01-06)

Fixes

  • Fix svg code included twice

...


Full changelog