Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

svg-symbol-sprite

scriptex37.3kMIT1.5.2

A script to generate a symbol sprite from SVG files

Sprite, SVG Sprite, SVG Symbol, Image sprite, SVG Sprite Generator, Image sprite Generator, SVG Symbol Sprite Generator

readme

Github Build Codacy Badge Codebeat Badge CodeFactor Badge DeepScan grade Analytics

SVG Symbol Sprite

Create an SVG symbol sprite from your SVG files.

GitHub stars GitHub forks GitHub watchers GitHub followers

Code stats

GitHub code size in bytes GitHub repo size GitHub language count GitHub top language GitHub last commit

A Node.js CLI tool which creates an optimized SVG symbol sprite out of a folder full of SVG files.

Provides handy defaults so you don't have to waste time.

All available options can be tweaked. You can even supply your own SVGO config.

This tool is heavily inspried by sprite.sh

Installation

npm i svg-symbol-sprite -g

# or

yarn global add svg-symbol-sprite

Options

Argument Description Default value
-i, --input Specifies input dir "." (current directory)
-o, --output Specifies output file "./sprite.svg"
-v, --viewbox Specifies viewBox attribute (parsed from each icon)
-p, --prefix Specifies prefix for id attribute "icon-"
-c, --config Absolute path to the SVGO config file or "false" -
-a, --attrs Attributes for the SVG element "aria-hidden="true""
-s, --style Inline style for the SVG element "width: 0; height: 0; position: absolute;"
Usage: svg-symbol-sprite [options]

Options:
    -i, --input     Specifies input dir (current dir by default)
    -o, --output    Specifies output file ("./sprite.svg" by default)
    -v, --viewbox   Specifies viewBox attribute (parsed by default)
    -p, --prefix    Specifies prefix for id attribute ("icon-" by default)
    -c, --config    Absolute path to the SVGO config file or "false"
    -a, --attrs     Attributes for the SVG element ('xmlns="http://www.w3.org/2000/svg" aria-hidden="true"' by default)
    -s, --style     Inline style for the SVG element ("width: 0; height: 0; position: absolute;" by default)

Usage as a package.json script

The tool can be also used as a package.json script. You need to add it to the devDependencies of your project's package.json.

{
    "scripts": {
        "svg-sprite": "svg-symbol-sprite -i ./assets/svgs -o ./dist/sprite.svg"
    }
}
npm run svg-sprite

# or

yarn svg-sprite

Usage without installation (with npx)

The tool can be also used without installing it:

npx svg-symbol-sprite -i ./assets/svgs -o ./dist/sprite.svg

SVG Optimization

svg-symbol-sprite optimizes the input SVG files using SVGO and an opinionated configuration file. In order to customize the SVGO config, one can do so by using the -c or --config option and an absolute path to the SVGO config file.

If you wish to completely disable the SVGO files optimization, pass "false" to the --config option.

Accessibility

svg-symbol-sprite does not help with SVG icons' accessibility. This is your responsibility as a developer - you should make sure that your SVGs contain relevant title and id attributes.

LICENSE

MIT


Connect with me:

                     

Support and sponsor my work:

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

1.5.2

10 May 2024

  • Update CHANGELOG.md with the latest changes 8fff102
  • Release 1.5.2 e4ab19d

1.5.1

10 May 2024

  • Unpin dependencies a4cf646
  • Update dependency release-it to v17.2.1 10933f5
  • Update CHANGELOG.md with the latest changes 655f6c8

1.5.0

22 April 2024

  • Bump ip from 1.1.8 to 1.1.9 #52
  • Update dependency commander to v12 #51
  • Update dependency release-it to v17 #46
  • Update actions/setup-node action to v4 #44
  • Correctly use SVGO config (#54) 71ff412
  • Update dependency release-it to v17.0.3 46be66a
  • Update dependency release-it to v17.2.0 577b428

1.4.1

19 September 2023

  • Fix typo in README's Usage without installation (with npx) [#43`](https://github.com/scriptex/svg-symbol-sprite/pull/43)
  • Update actions/checkout action to v4 #41
  • Bump word-wrap from 1.2.3 to 1.2.4 #39
  • Bump semver from 7.3.8 to 7.5.3 #38
  • Update dependency release-it to v16 #37
  • Update dependency commander to v11 #36
  • Update dependency @types/tape to v5 #35
  • Bump vm2 from 3.9.17 to 3.9.18 #33
  • Bump vm2 from 3.9.16 to 3.9.17 #32
  • Bump vm2 from 3.9.15 to 3.9.16 #31
  • Bump vm2 from 3.9.11 to 3.9.15 #30
  • Update dependency typescript to v5 #29
  • Bump cacheable-request from 10.2.2 to 10.2.7 #28
  • Bump http-cache-semantics from 4.1.0 to 4.1.1 #27
  • Update dependency commander to v10 #26
  • Upgrade packages e128d60
  • Update dependency release-it to v15.10.5 c9ef096
  • Update dependency release-it to v15.9.1 2d8a66d

1.4.0

14 November 2022

  • Remove empty style attribute 4e77170
  • Update CHANGELOG.md with the latest changes b21af7c
  • Release 1.4.0 d9c5e1d

1.3.0

10 November 2022

  • Add ability to modify SVG props, style and SVGO config #23
  • Update CHANGELOG.md with the latest changes a5ccbb9
  • Release 1.3.0 a476bec
  • Ignore all assets 4801d38

1.2.2

7 November 2022

  • Update dependency svgo to v3 #21
  • Update dependency release-it to v15.4.3 88541a0
  • Fix the URL to the documentation 2b09efa
  • Update CHANGELOG.md with the latest changes ec1aa24

1.2.0

30 September 2022

  • Update metadata #20
  • Update dependency release-it to v15.4.2 3a66588
  • Update CHANGELOG.md with the latest changes d077dbe
  • Update dependency typescript to v4.8.4 58b78c4

1.0.5

1 September 2022

  • Use double quotes in attributes c774b1e
  • Update dependency release-it to v15.1.2 167fead
  • Update dependency release-it to v15.1.4 31577e9

1.0.4

12 July 2022

  • Fix the path to the default config #19
  • Bump parse-url from 6.0.0 to 6.0.2 #17
  • Update dependency release-it to v15 #15
  • Bump minimist from 1.2.5 to 1.2.6 #14
  • Update actions/checkout action to v3 #11
  • Update actions/setup-node action to v3 #10
  • Update dependency commander to v9 #9
  • Bump node-fetch from 2.6.6 to 2.6.7 #8
  • Update dependency release-it to v14.12.1 #6
  • Update dependency release-it to v15.1.1 b66ade6
  • Upgrade packages 03d7514
  • Update dependency release-it to v14.14.3 c1f4c75

1.0.3

4 January 2022

1.0.2

4 January 2022

1.0.1

4 January 2022

  • Correctly load and use SVGO config #4
  • Update CHANGELOG.md with the latest changes a938b8c
  • Update dependency @types/node to v16.11.18 6707546
  • Update dependency @types/node to v16.11.17 663ff0e

1.0.0

6 December 2021