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-cliVerified import paths — ran on the pinned version, not inferred.
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.
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.
Correct: `svg2sprite ... --stripAttrs id --stripAttrs viewBox`. Incorrect: `svg2sprite ... --stripAttrs id,viewBox`.
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.
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`).
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`.