{"id":17067,"library":"svg2sprite-cli","title":"SVG Sprite Command Line Interface","description":"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.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/mrmlnc/svg2sprite-cli","tags":["javascript","svg","symbol","sprite","spritesheet","generator","icon","icons"],"install":[{"cmd":"npm install svg2sprite-cli","lang":"bash","label":"npm"},{"cmd":"yarn add svg2sprite-cli","lang":"bash","label":"yarn"},{"cmd":"pnpm add svg2sprite-cli","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core library for SVG sprite generation; svg2sprite-cli is a wrapper around it.","package":"svg2sprite","optional":false}],"imports":[{"note":"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.","wrong":"import { svg2sprite } from 'svg2sprite-cli'","symbol":"svg2sprite","correct":"$ npm i -g svg2sprite-cli"},{"note":"The `svg2sprite` command should be run directly after global installation, not via `node` on the package executable.","wrong":"$ node svg2sprite-cli <source-directory> <dist-file>","symbol":"Usage","correct":"$ svg2sprite <source-directory> <dist-file> [options]"},{"note":"Command-line options are prefixed with `--` or `-`. Glob patterns for `--ignore` may require single quotes in some shell environments to prevent shell expansion.","symbol":"Options","correct":"$ svg2sprite images/svg out/sprite.svg --iconPrefix=prefix --ignore 'rainbow.svg'"}],"quickstart":{"code":"# Install the CLI globally\nnpm i -g svg2sprite-cli\n\n# Create a directory for your SVG icons\nmkdir -p src/icons\n\n# Create some dummy SVG files (replace with your actual icons)\necho '<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\necho '<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\n\n# Create an output directory\nmkdir -p dist\n\n# Generate the SVG sprite, ignoring one icon and adding a prefix\n# The output will be in dist/sprite.svg\nsvg2sprite src/icons dist/sprite.svg --ignore 'info.svg' --iconPrefix='my-icon-'\n\n# You can verify the generated sprite content\ncat dist/sprite.svg\n\n# Example of how to use the sprite in HTML (conceptual):\n# <svg><use xlink:href=\"/dist/sprite.svg#my-icon-check\"></use></svg>","lang":"bash","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Correct: `svg2sprite ... --stripAttrs id --stripAttrs viewBox`. Incorrect: `svg2sprite ... --stripAttrs id,viewBox`.","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Glob 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 `**`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"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`).","cause":"The `svg2sprite-cli` package was not installed globally, or the global `node_modules` bin directory is not in your system's PATH.","error":"command not found: svg2sprite"},{"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`.","cause":"The provided source directory path (`<source-directory>`) either does not exist, is misspelled, or is not accessible from the current working directory.","error":"Error: The source directory does not exist."}],"ecosystem":"npm","meta_description":null}