Registry / devops / svg2sprite-cli

svg2sprite-cli

JSON →
library2.0.1jsnpmunverified

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.

npm install svg2sprite-cli
INSTALL
IMPORT
SIG · SVG2SPRITE-CLI
S
svg2sprite-cli
devopsjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

svg2sprite
$ npm i -g svg2sprite-cli
import { svg2sprite } from 'svg2sprite-cli'
This package is a CLI tool and is primarily used via its globally installed `svg2sprite` command. It does not export modules for programmatic JavaScript/TypeScript import.
Usage
$ svg2sprite <source-directory> <dist-file> [options]
$ node svg2sprite-cli <source-directory> <dist-file>
The `svg2sprite` command should be run directly after global installation, not via `node` on the package executable.
Options
$ svg2sprite images/svg out/sprite.svg --iconPrefix=prefix --ignore 'rainbow.svg'
Command-line options are prefixed with `--` or `-`. Glob patterns for `--ignore` may require single quotes in some shell environments to prevent shell expansion.

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>
svg2sprite --version
Debug
Known issues
breakingThe update to `svg2sprite@2.0.0` in `svg2sprite-cli@2.0.0` indicates potential breaking changes in the underlying sprite generation logic or output format. While the CLI's command-line interface might remain compatible, the generated SVG sprite's structure, attributes, or behavior could have changed due to the major version bump of its core dependency.
fix
Review the changelog of the `svg2sprite` library (not `svg-sprite`) for specific changes if migrating from `svg2sprite-cli@1.x`. Test generated sprites thoroughly for compatibility with your existing CSS/HTML usage.
affects: >=2.0.0
gotchaWhen specifying multiple attributes to remove using `--stripAttrs`, the flag must be repeated for each attribute. Providing a comma-separated list or multiple values to a single `--stripAttrs` instance will not work as expected.
fix
Correct: `svg2sprite ... --stripAttrs id --stripAttrs viewBox`. Incorrect: `svg2sprite ... --stripAttrs id,viewBox`.
affects: >=1.0.0
gotchaGlob patterns used with options like `--ignore` might be interpreted by the shell before being passed to `svg2sprite-cli`. This can lead to unexpected behavior if the shell expands the glob, especially with complex patterns like `**`.
fix
Always wrap glob patterns in single quotes (e.g., `--ignore '*.svg'` or `--ignore 'icons/**/*.svg'`) to ensure they are passed literally to the CLI for proper interpretation.
affects: >=1.0.0
Errors
Common errors & fixes
command not found: svg2sprite
The `svg2sprite-cli` package was not installed globally, or the global `node_modules` bin directory is not in your system's PATH.
fix
Install the package globally using `npm i -g svg2sprite-cli` or `yarn global add svg2sprite-cli`. Ensure your system's PATH includes the directory where global npm/yarn executables are installed (e.g., `/usr/local/bin` or `$HOME/.npm-global/bin`).
Error: The source directory does not exist.
The provided source directory path (`<source-directory>`) either does not exist, is misspelled, or is not accessible from the current working directory.
fix
Verify the source directory path is correct and exists. Use an absolute path or a path relative to where you are running the `svg2sprite` command. Example: `svg2sprite ./src/icons ./dist/sprite.svg`.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
svg2spriterequiredCore library for SVG sprite generation; svg2sprite-cli is a wrapper around it.
Agent activity
2 hits · last 30 days
node
2
Resources
svg2sprite-cli — npm install svg2sprite-cli · libregistry