1 | svg-sprite [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency Status][depstat-image]][depstat-url] [![Development Dependency Status][devdepstat-image]][devdepstat-url]
|
2 | ==========
|
3 |
|
4 | This file is part of the documentation of *svg-sprite* — a free low-level Node.js module that **takes a bunch of SVG files**, optimizes them and creates **SVG sprites** of several types. The package is [hosted on GitHub](https://github.com/jkphl/svg-sprite).
|
5 |
|
6 |
|
7 | Command line usage
|
8 | ------------------
|
9 |
|
10 | You may use *svg-sprite* as a command line tool. Type `svg-sprite --help` to get all the available options:
|
11 |
|
12 | ```bash
|
13 | Usage: svg-sprite [options] files
|
14 |
|
15 | Options:
|
16 | --version Show version number [boolean]
|
17 | --help Display this help information [boolean]
|
18 | -D, --dest Main output directory (base path) [default: "."]
|
19 | -C, --config Path to external JSON config file
|
20 | -l, --log Logging verbosity ("info", "verbose" or "debug")
|
21 | --shape-id-separator Separator for traversing a directory structure into a shape ID [default: "--"]
|
22 | --shape-id-generator ID generation callback [via CLI only template strings] [default: "%s"]
|
23 | --shape-id-pseudo Separator for CSS pseudo classes [default: "~"]
|
24 | --shape-id-whitespace Whitespace replacement string for shape IDs [default: "_"]
|
25 | -w, --shape-dim-width Maximum shape width in pixels [default: 2000]
|
26 | -h, --shape-dim-height Maximum shape height in pixels [default: 2000]
|
27 | --shape-dim-precision Precision (decimal places) for dimension calculations [default: 2]
|
28 | --shape-dim-attributes Whether to add width and height attributes to the shapes [boolean] [default: false]
|
29 | -p, --shape-spacing-padding Padding around shape (up to 4 x comma-separated) [default: "0,0,0,0"]
|
30 | -b, --shape-spacing-box Box sizing strategy ("content", "padding" or "icon") [default: "content"]
|
31 | -m, --shape-meta Path to YAML file with meta information
|
32 | -a, --shape-align Path to YAML file with alignment information
|
33 | --ims, --shape-dest Path to output directory for intermediate SVG files
|
34 | --shape-transform Comma-separated list of predefined transformers (see docs) [default: "svgo"]
|
35 | --shape-transform-* External JSON config files for named transformers
|
36 | --svg-xmldecl Whether to include an XML declaration in SVG files [boolean] [default: true]
|
37 | --svg-doctype Whether to include a doctype declaration in SVG files [boolean] [default: true]
|
38 | --svg-namespace-ids Whether to apply ID namespacing to the sprite [boolean] [default: true]
|
39 | --svg-namespace-classnames Whether to apply CSS class namespacing to the sprite [boolean] [default: true]
|
40 | --svg-dimattrs Whether to add width and height attributes to the sprite [boolean] [default: true]
|
41 | --svg-rootattrs Custom root attributes for the outermost <svg> element (external JSON file)
|
42 | --svg-precision Floating point precision for CSS positioning values [default: -1]
|
43 |
|
44 | -c, --css Activates the «css» mode [boolean] [default: false]
|
45 | --css-dest Mode specific output directory [default: "css"]
|
46 | --cl, --css-layout Sprite layout ("vertical"/"horizontal"/"diagonal"/"packed") [default: "packed"]
|
47 | --css-common Common CSS rule selector for all shapes [default: null]
|
48 | --css-mixin Preprocessor mixin name with properties for all shapes [default: null]
|
49 | --css-prefix CSS selector prefix for all shapes (including placeholders) [default: ".svg-%s"]
|
50 | --css-dimensions CSS selector suffix for shape dimension rules ("" for inline) [default: "-dims"]
|
51 | --cs, --css-sprite Sprite path and filename (relative to --css-dest) [default: "svg/sprite.css.svg"]
|
52 | --css-bust Enable cache busting [boolean] [default: true]
|
53 | --ccss, --css-render-css Whether to render a CSS stylesheet [boolean] [default: false]
|
54 | --css-render-css-template CSS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.css"]
|
55 | --css-render-css-dest CSS stylesheet destination (relative to the --css-dest) [default: "sprite.css"]
|
56 | --cscss, --css-render-scss Whether to render a Sass stylesheet (SCSS) [boolean] [default: false]
|
57 | --css-render-scss-template Sass stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.scss"]
|
58 | --css-render-scss-dest Sass stylesheet destination (relative to the --css-dest) [default: "sprite.scss"]
|
59 | --cless, --css-render-less Whether to render a LESS stylesheet [boolean] [default: false]
|
60 | --css-render-less-template LESS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.less"]
|
61 | --css-render-less-dest LESS stylesheet destination (relative to the --css-dest) [default: "sprite.less"]
|
62 | --cstyl, --css-render-styl Whether to render a Stylus stylesheet [boolean] [default: false]
|
63 | --css-render-styl-template Stylus stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.styl"]
|
64 | --css-render-styl-dest styl stylesheet destination (relative to the --css-dest) [default: "sprite.styl"]
|
65 | --css-render-* Custom output renderings
|
66 | --css-render-*-template Custom output Mustache template (relative to svg-sprite basedir)
|
67 | --css-render-*-dest Custom output destination (relative to the --css-dest)
|
68 | --cx, --css-example Whether to render an example HTML document [boolean] [default: false]
|
69 | --css-example-template HTML document Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.html"]
|
70 | --css-example-dest HTML document destination (relative to the --css-dest) [default: "sprite.css.html"]
|
71 |
|
72 | -v, --view Activates the «view» mode [boolean] [default: false]
|
73 | --view-dest Mode specific output directory [default: "view"]
|
74 | --vl, --view-layout Sprite layout ("vertical"/"horizontal"/"diagonal"/"packed") [default: "packed"]
|
75 | --view-common Common CSS rule selector for all shapes [default: null]
|
76 | --view-mixin Preprocessor mixin name with properties for all shapes [default: null]
|
77 | --view-prefix CSS selector prefix for all shapes (including placeholders) [default: ".svg-%s"]
|
78 | --view-dimensions CSS selector suffix for shape dimension rules ("" for inline) [default: "-dims"]
|
79 | --vs, --view-sprite Sprite path and filename (relative to --view-dest) [default: "svg/sprite.css.svg"]
|
80 | --view-bust Enable cache busting [boolean] [default: true]
|
81 | --vcss, --view-render-css Whether to render a CSS stylesheet [boolean] [default: false]
|
82 | --view-render-css-template CSS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.css"]
|
83 | --view-render-css-dest CSS stylesheet destination (relative to the --view-dest) [default: "sprite.css"]
|
84 | --vscss, --view-render-scss Whether to render a Sass stylesheet (SCSS) [boolean] [default: false]
|
85 | --view-render-scss-template Sass stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.scss"]
|
86 | --view-render-scss-dest Sass stylesheet destination (relative to the --view-dest) [default: "sprite.scss"]
|
87 | --vless, --view-render-less Whether to render a LESS stylesheet [boolean] [default: false]
|
88 | --view-render-less-template LESS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.less"]
|
89 | --view-render-less-dest LESS stylesheet destination (relative to the --view-dest) [default: "sprite.less"]
|
90 | --vstyl, --view-render-styl Whether to render a Stylus stylesheet [boolean] [default: false]
|
91 | --view-render-styl-template Stylus stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.styl"]
|
92 | --view-render-styl-dest styl stylesheet destination (relative to the --view-dest) [default: "sprite.styl"]
|
93 | --view-render-* Custom output renderings
|
94 | --view-render-*-template Custom output Mustache template (relative to svg-sprite basedir)
|
95 | --view-render-*-dest Custom output destination (relative to the --view-dest)
|
96 | --vx, --view-example Whether to render an example HTML document [boolean] [default: false]
|
97 | --view-example-template HTML document Mustache template (relative to svg-sprite basedir) [default: "tmpl/view/sprite.html"]
|
98 | --view-example-dest HTML document destination (relative to the --view-dest) [default: "sprite.view.html"]
|
99 |
|
100 | -d, --defs Activates the «defs» mode [boolean] [default: false]
|
101 | --defs-dest Mode specific output directory [default: "defs"]
|
102 | --defs-prefix CSS selector prefix for all shapes (including placeholders) [default: ".svg-%s"]
|
103 | --defs-dimensions CSS selector suffix for shape dimension rules ("" for inline) [default: "-dims"]
|
104 | --ds, --defs-sprite Sprite path and filename (relative to --defs-dest) [default: "svg/sprite.css.svg"]
|
105 | --defs-bust Enable cache busting [boolean] [default: false]
|
106 | --dcss, --defs-render-css Whether to render a CSS stylesheet [boolean] [default: false]
|
107 | --defs-render-css-template CSS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.css"]
|
108 | --defs-render-css-dest CSS stylesheet destination (relative to the --defs-dest) [default: "sprite.css"]
|
109 | --dscss, --defs-render-scss Whether to render a Sass stylesheet (SCSS) [boolean] [default: false]
|
110 | --defs-render-scss-template Sass stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.scss"]
|
111 | --defs-render-scss-dest Sass stylesheet destination (relative to the --defs-dest) [default: "sprite.scss"]
|
112 | --dless, --defs-render-less Whether to render a LESS stylesheet [boolean] [default: false]
|
113 | --defs-render-less-template LESS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.less"]
|
114 | --defs-render-less-dest LESS stylesheet destination (relative to the --defs-dest) [default: "sprite.less"]
|
115 | --dstyl, --defs-render-styl Whether to render a Stylus stylesheet [boolean] [default: false]
|
116 | --defs-render-styl-template Stylus stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.styl"]
|
117 | --defs-render-styl-dest styl stylesheet destination (relative to the --defs-dest) [default: "sprite.styl"]
|
118 | --defs-render-* Custom output renderings
|
119 | --defs-render-*-template Custom output Mustache template (relative to svg-sprite basedir)
|
120 | --defs-render-*-dest Custom output destination (relative to the --defs-dest)
|
121 | --di, --defs-inline Create sprite variant suitable for inline embedding [boolean] [default: false]
|
122 | --dx, --defs-example Whether to render an example HTML document [boolean] [default: false]
|
123 | --defs-example-template HTML document Mustache template (relative to svg-sprite basedir) [default: "tmpl/defs/sprite.html"]
|
124 | --defs-example-dest HTML document destination (relative to the --defs-dest) [default: "sprite.defs.html"]
|
125 |
|
126 | -s, --symbol Activates the «symbol» mode [boolean] [default: false]
|
127 | --symbol-dest Mode specific output directory [default: "symbol"]
|
128 | --symbol-prefix CSS selector prefix for all shapes (including placeholders) [default: ".svg-%s"]
|
129 | --symbol-dimensions CSS selector suffix for shape dimension rules ("" for inline) [default: "-dims"]
|
130 | --ss, --symbol-sprite Sprite path and filename (relative to --css-dest) [default: "svg/sprite.css.svg"]
|
131 | --symbol-bust Enable cache busting [boolean] [default: false]
|
132 | --scss, --symbol-render-css Whether to render a CSS stylesheet [boolean] [default: false]
|
133 | --symbol-render-css-template CSS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.css"]
|
134 | --symbol-render-css-dest CSS stylesheet destination (relative to the --symbol-dest) [default: "sprite.css"]
|
135 | --sscss, --symbol-render-scss Whether to render a Sass stylesheet (SCSS) [boolean] [default: false]
|
136 | --symbol-render-scss-template Sass stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.scss"]
|
137 | --symbol-render-scss-dest Sass stylesheet destination (relative to the --symbol-dest) [default: "sprite.scss"]
|
138 | --sless, --symbol-render-less Whether to render a LESS stylesheet [boolean] [default: false]
|
139 | --symbol-render-less-template LESS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.less"]
|
140 | --symbol-render-less-dest LESS stylesheet destination (relative to the --symbol-dest) [default: "sprite.less"]
|
141 | --sstyl, --symbol-render-styl Whether to render a Stylus stylesheet [boolean] [default: false]
|
142 | --symbol-render-styl-template Stylus stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.styl"]
|
143 | --symbol-render-styl-dest styl stylesheet destination (relative to the --symbol-dest) [default: "sprite.styl"]
|
144 | --symbol-render-* Custom output renderings
|
145 | --symbol-render-*-template Custom output Mustache template (relative to svg-sprite basedir)
|
146 | --symbol-render-*-dest Custom output destination (relative to the --symbol-dest)
|
147 | --si, --symbol-inline Create sprite variant suitable for inline embedding [boolean] [default: false]
|
148 | --sx, --symbol-example Whether to render an example HTML document [boolean] [default: false]
|
149 | --symbol-example-template HTML document Mustache template (relative to svg-sprite basedir) [default: "tmpl/symbol/sprite.html"]
|
150 | --symbol-example-dest HTML document destination (relative to the --css-dest) [default: "sprite.symbol.html"]
|
151 |
|
152 | -S, --stack Activates the «stack» mode [boolean] [default: false]
|
153 | --stack-dest Mode specific output directory [default: "stack"]
|
154 | --stack-prefix CSS selector prefix for all shapes (including placeholders) [default: ".svg-%s"]
|
155 | --stack-dimensions CSS selector suffix for shape dimension rules ("" for inline) [default: "-dims"]
|
156 | --Ss, --stack-sprite Sprite path and filename (relative to --css-dest) [default: "svg/sprite.css.svg"]
|
157 | --stack-bust Enable cache busting [boolean] [default: false]
|
158 | --Scss, --stack-render-css Whether to render a CSS stylesheet [boolean] [default: false]
|
159 | --stack-render-css-template CSS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.css"]
|
160 | --stack-render-css-dest CSS stylesheet destination (relative to the --stack-dest) [default: "sprite.css"]
|
161 | --Sscss, --stack-render-scss Whether to render a Sass stylesheet (SCSS) [boolean] [default: false]
|
162 | --stack-render-scss-template Sass stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.scss"]
|
163 | --stack-render-scss-dest Sass stylesheet destination (relative to the --stack-dest) [default: "sprite.scss"]
|
164 | --Sless, --stack-render-less Whether to render a LESS stylesheet [boolean] [default: false]
|
165 | --stack-render-less-template LESS stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.less"]
|
166 | --stack-render-less-dest LESS stylesheet destination (relative to the --stack-dest) [default: "sprite.less"]
|
167 | --Sstyl, --stack-render-styl Whether to render a Stylus stylesheet [boolean] [default: false]
|
168 | --stack-render-styl-template Stylus stylesheet Mustache template (relative to svg-sprite basedir) [default: "tmpl/css/sprite.styl"]
|
169 | --stack-render-styl-dest styl stylesheet destination (relative to the --stack-dest) [default: "sprite.styl"]
|
170 | --stack-render-* Custom output renderings
|
171 | --stack-render-*-template Custom output Mustache template (relative to svg-sprite basedir)
|
172 | --stack-render-*-dest Custom output destination (relative to the --stack-dest)
|
173 | --Sx, --stack-example Whether to render an example HTML document [boolean] [default: false]
|
174 | --stack-example-template HTML document Mustache template (relative to svg-sprite basedir) [default: "tmpl/stack/sprite.html"]
|
175 | --stack-example-dest HTML document destination (relative to the --css-dest) [default: "sprite.stack.html"]
|
176 |
|
177 | --variables Path to external JSON file with Mustache variable definitions
|
178 | ```
|
179 |
|
180 | ### Examples
|
181 |
|
182 | Both the following commands are doing the same (with the second one using the shorter argument syntax): They use the SVG files found in the directory `"assets"`, create a CSS sprite of them and write them to the subdirectory `"out"` along with accompanying CSS stylesheets.
|
183 |
|
184 | ```bash
|
185 | $ svg-sprite --css --css-render-css --css-example --dest=out assets/*.svg
|
186 | $ svg-sprite -cD out --ccss --cx assets/*.svg
|
187 | ```
|
188 |
|
189 | The next one renders a Sass stylesheet (instead of plain CSS) and adds a 10px padding around all shapes in the sprite:
|
190 |
|
191 | ```bash
|
192 | $ svg-sprite -cD out --cscss -p 10 assets/*.svg
|
193 | ```
|
194 |
|
195 | Using config file (config.json in project base path) instead of command line options. Config file can be generated [with the online configurator](http://jkphl.github.io/svg-sprite/#json).
|
196 |
|
197 | ```bash
|
198 | $ svg-sprite --config config.json assets/*.svg
|
199 | ```
|
200 |
|
201 | ### Advanced globbing
|
202 |
|
203 | Some shells don't support the double-star character `**` for matching files in an arbitrary directory depth, so you should wrap your glob expression in single quotes when using it in your pattern. This will prevent your shell from trying to resolve it and rather delegate globbing to Node instead (which does support the `**` character).
|
204 |
|
205 | ```bash
|
206 | $ svg-sprite --config config.json 'assets/**/*.svg'
|
207 | ```
|
208 |
|
209 | The CLI typically uses only the basename of files for constructing the shape IDs in your sprite. That is, if an SVG source file is found at the path `assets/path/to/source.svg`, the shape inside the sprite will have the ID `source`. If you want to set a "base directory" from where ID traversal should start, simply add a symbolic link to that very same directory (`"./"`) in your pattern:
|
210 |
|
211 | ```bash
|
212 | $ svg-sprite --config config.json 'assets/./**/*.svg'
|
213 | ```
|
214 |
|
215 | The spriter will then use `path/to/source` for ID creation, resulting in the shape ID `path--to--source` (assuming you don't override the default shape ID generator function). Please be aware that the described feature won't work if the matched SVG files are symbolic links themselves.
|
216 |
|
217 | ### Inlined shape dimensions
|
218 |
|
219 | To get the shape dimensions inlined into the main shape CSS rules, you need to pass an empty dimension selector suffix. There are two ways of doing so:
|
220 |
|
221 | ```bash
|
222 | $ svg-sprite -cD out --css-dimensions "" --ccss assets/*.svg
|
223 | $ svg-sprite -cD out --css-dimensions= --ccss assets/*.svg
|
224 | ```
|
225 |
|
226 |
|
227 | [npm-url]: https://npmjs.org/package/svg-sprite
|
228 | [npm-image]: https://badge.fury.io/js/svg-sprite.png
|
229 |
|
230 | [travis-url]: http://travis-ci.org/jkphl/svg-sprite
|
231 | [travis-image]: https://secure.travis-ci.org/jkphl/svg-sprite.png
|
232 |
|
233 | [coveralls-url]: https://coveralls.io/r/jkphl/svg-sprite
|
234 | [coveralls-image]: https://img.shields.io/coveralls/jkphl/svg-sprite.svg
|
235 |
|
236 | [depstat-url]: https://david-dm.org/jkphl/svg-sprite#info=dependencies
|
237 | [depstat-image]: https://david-dm.org/jkphl/svg-sprite.svg
|
238 | [devdepstat-url]: https://david-dm.org/jkphl/svg-sprite#info=devDependencies
|
239 | [devdepstat-image]: https://david-dm.org/jkphl/svg-sprite/dev-status.svg
|