SVG Sprite Command Line Interface

2.0.1 · active · verified Wed Apr 22

svg2sprite-cli provides a command-line interface for the `svg2sprite` library, designed to generate SVG sprites from a collection of individual SVG files. The current stable version is 2.0.1, though the underlying `svg2sprite` library, which `svg2sprite-cli` wraps, has not seen significant updates in approximately 9 years. The package itself has a very slow release cadence, with major version updates typically reflecting updates to its core dependency rather than new features in the CLI layer. Its key differentiator is providing a straightforward, opinionated command-line utility for SVG sprite generation, avoiding the need for direct programmatic integration of `svg2sprite` into a build system.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global installation, creation of dummy SVG source files, and generating an SVG sprite with options for ignoring files and applying an icon prefix, then displaying its content.

# Install the CLI globally
npm i -g svg2sprite-cli

# Create a directory for your SVG icons
mkdir -p src/icons

# Create some dummy SVG files (replace with your actual icons)
echo '<svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/></svg>' > src/icons/check.svg
echo '<svg viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 15h2v-6h-2v6zm0-8h2V7h-2v2z"/></svg>' > src/icons/info.svg

# Create an output directory
mkdir -p dist

# Generate the SVG sprite, ignoring one icon and adding a prefix
# The output will be in dist/sprite.svg
svg2sprite src/icons dist/sprite.svg --ignore 'info.svg' --iconPrefix='my-icon-'

# You can verify the generated sprite content
cat dist/sprite.svg

# Example of how to use the sprite in HTML (conceptual):
# <svg><use xlink:href="/dist/sprite.svg#my-icon-check"></use></svg>

view raw JSON →