npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-plugin-svg-spritesheet

v0.7.2

Published

Vite plugin for SVG spritesheets with SVGO

Readme

vite-plugin-svg-spritesheet

npm version Build Status License: MIT

Type-safe, build-time SVG spritesheets for Vite projects
Generate a single optimized spritesheet with automatic TypeScript definitions, directory-based overrides, optional CSS variable theming — all with zero runtime overhead.

Why this plugin?

This plugin was built to support needs that I couldn't find in existing solutions:

  • Layered directory overrides: Use multiple directories with override priority, enabling clean layering (e.g. base icons overridden by custom sets).
  • Theming without duplication: Replaces fill and color with CSS variables using initial fallbacks, allowing flexible theming (like currentColor) without duplicating icons.

Key benefits

  • No runtime dependencies: Output is generated during build, keeping bundles clean.
  • Automatic type generation: Ensures type safety and editor autocomplete.
  • Directory-based overrides: Supports clean layering of base and custom icons.
  • Theming support: Replaces static fill and stroke with CSS variables and fallbacks.
  • Customizable symbol IDs: Control naming with directory-aware defaults or custom functions.

Quick start

npm install vite-plugin-svg-spritesheet --save-dev
// vite.config.ts
import { defineConfig } from 'vite';
import {
  generateStringUnion,
  svgSpritesheet,
} from 'vite-plugin-svg-spritesheet';

export default defineConfig({
  plugins: [
    svgSpritesheet({
      include: ['src/assets/icons/base', 'src/assets/icons/theme'],
      output: 'public/spritesheet.svg',
      svgoConfig: {
        plugins: [
          // An issue when with Figma's exports might be that colors are applied
          // via the `style` attribute, making it impossible to override it with
          // the parent's `currentColor`.
          'convertStyleToAttrs',
          // To generate unique IDs for each <symbol> in case they are
          // internally referenced, e.g. a gradient in <defs>.
          'prefixIds',
        ],
      },
      types: {
        generateTypes: generateStringUnion('IconName'),
        output: 'src/generated/icons.ts',
      },
    }),
  ],
});

TypeScript integration

The plugin supports automatic type generation, enabling editor autocomplete and safer, maintainable icon usage:

export type IconName = 'icon-sm-add' | 'icon-md-delete' | 'icon-lg-change';

export enum IconName {
  SM_ADD = 'icon-sm-add',
  MD_DELETE = 'icon-md-delete',
  LG_CHANGE = 'icon-lg-change',
}

You can also pass a custom function to generateTypes to control the output format.

Plugin Options

Below are the configuration options available for svgSpritesheet:

| Option | Type | Description | | ------------------------ | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | include | string \| string[] | Ordered list of directories to include. Later ones override earlier ones. | | exclude | string \| string[] | Glob patterns for files or directories to exclude. | | output | string | Output path for the generated SVG spritesheet. | | svgoConfig | object | SVGO configuration for optimization. | | symbolId.prefix | string | Prefix prepended to all symbol IDs. Defaults to "icon". | | symbolId.id | (filePath: string) => string | Custom function for the id attribute of the <symbol>. | | replaceColorAttributes | boolean | Replaces fill and stroke with a CSS variable for currentColor support. See the examples for this in action. | | types.output | string | Path for the generated TypeScript types. | | types.generateTypes | (map: SpriteMap) => string | Function that receives the sprite map and can return TypeScript types. The exported generateEnum and generateStringUnion functions can be used as well |

Framework integration

This repository includes usage examples for several frameworks in the /examples directory. These examples are self-contained and are not included in the published npm package.

Available examples

| Framework | Directory | Live demo | | --------- | -------------------------------- | ---------------------------------- | | Vanilla | /examples/vanilla | Open in StackBlitz | | Astro | /examples/astro | Open in StackBlitz | | Vue | /examples/vue | Open in StackBlitz |

Running locally

To run any example locally:

cd examples/<framework>
npm install
npm run dev

Replace <framework> with one of the supported options (e.g. vanilla, vue, astro).