UNPKG

7.56 kBMarkdownView Raw
1# webfont
2
3[![NPM version](https://img.shields.io/npm/v/webfont.svg)](https://www.npmjs.org/package/webfont)
4[![Travis Build Status](https://img.shields.io/travis/itgalaxy/webfont/master.svg?label=build)](https://travis-ci.org/itgalaxy/webfont)
5[![Build status](https://ci.appveyor.com/api/projects/status/a8absovr2r44w1oc?svg=true)](https://ci.appveyor.com/project/evilebottnawi/webfont)
6[![dependencies Status](https://david-dm.org/itgalaxy/webfont/status.svg)](https://david-dm.org/itgalaxy/webfont)
7[![devDependencies Status](https://david-dm.org/itgalaxy/webfont/dev-status.svg)](https://david-dm.org/itgalaxy/webfont?type=dev)
8[![Greenkeeper badge](https://badges.greenkeeper.io/itgalaxy/webfont.svg)](https://greenkeeper.io)
9
10Generator of fonts from SVG icons.
11
12Features:
13
14* Supported font formats: `WOFF2`, `WOFF`, `EOT`, `TTF` and `SVG`.
15* Support configuration Files - use a `JavaScript`, `JSON` or `YAML` file to specify configuration information for an entire directory and all of its subdirectories.
16* Supported browsers: IE8+.
17* Allows to use custom templates (example `css`, `scss` and etc).
18* No extra dependencies as `gulp`, `grunt` or other big tools.
19* Tested on all platforms (`linux`, `windows` and `osx`).
20* CLI.
21
22## Install
23
24```shell
25npm install --save-dev webfont
26```
27
28## Usage
29
30```js
31const webfont = require("webfont").default;
32
33webfont({
34 files: "src/svg-icons/**/*.svg",
35 fontName: "my-font-name"
36}).then(result => {
37 console.log(result);
38});
39```
40
41Or
42
43```js
44import webfont from "webfont";
45
46webfont({
47 files: "src/svg-icons/**/*.svg",
48 fontName: "my-font-name"
49}).then(result => {
50 console.log(result);
51});
52```
53
54## Options
55
56### `files`
57
58A file glob, or array of file globs.
59Ultimately passed to [fast-glob](https://github.com/mrmlnc/fast-glob) to figure out what files you want to get.
60
61`node_modules` and `bower_components` are always ignored.
62
63### `configFile`
64
65A `webfont` configuration object.
66
67### `fontName`
68
69Type: `String`
70Default: `webfont`
71
72The font family name you want.
73
74### `formats`
75
76Type: `Array`
77Default value: `['svg', 'ttf', 'eot', 'woff', 'woff2']`
78Possible values: `svg, ttf, eot, woff, woff2`.
79
80Font file types to generate.
81
82### `template`
83
84Type: `string`
85Default: `null`
86
87Possible values: `css`, `scss` (feel free to contribute). If you want to use custom template use this option.
88Example: `template: path.resolve(__dirname, './my-template.css')`.
89
90### `templateClassName`
91
92Type: `string`
93Default: `null`
94
95Default font class name.
96
97### `templateFontPath`
98
99Type: `string`
100Default: `./`
101
102Path to generated fonts in the `CSS` file.
103
104### `templateFontName`
105
106Type: `string`
107
108Default value getting from `fontName` options, but you can specify any value.
109
110### `glyphTransformFn`
111
112Type: `function`
113Default: `null`
114
115If you need transform glyph metadata (e.g. titles of CSS classes) before transferred in style template for your icons, you can use this option with glyphs metadata object.
116
117Example:
118
119```js
120glyphTransformFn: obj => {
121 obj.name += "_transform";
122
123 return obj;
124};
125```
126
127### `fontId`
128
129### `fontStyle`
130
131### `fontWeight`
132
133### `fixedWidth`
134
135### `centerHorizontally`
136
137### `normalize`
138
139### `fontHeight`
140
141### `round`
142
143### `descent`
144
145### `ascent`
146
147### `startUnicode`
148
149### `prependUnicode`
150
151Options that are passed directly to [svgicons2svgfont](https://github.com/nfroidure/svgicons2svgfont).
152Option `fontName` for `svgicons2svgfont` taken from above `fontName` argument.
153
154## Command Line Interface
155
156The interface for command-line usage is fairly simplistic at this stage, as seen in the following usage section.
157
158### Usage
159
160`webfont --help` prints the CLI documentation.
161
162### Options
163
164```sh
165 Generator of fonts from svg icons, svg icons to svg font, svg font to ttf, ttf to eot, ttf to woff, ttf to woff2
166
167 Usage: webfont [input] [options]
168
169 Input: File(s) or glob(s).
170
171 If an input argument is wrapped in quotation marks, it will be passed to "fast-glob"
172 for cross-platform glob support.
173
174 Options:
175
176 --config
177
178 Path to a specific configuration file (JSON, YAML, or CommonJS)
179 or the name of a module in `node_modules` that points to one.
180 If no `--config` argument is provided, webfont will search for
181 configuration files in the following places, in this order:
182 - a `webfont` property in `package.json`
183 - a `.webfontrc` file (with or without filename extension:
184 `.json`, `.yaml`, and `.js` are available)
185 - a `webfont.config.js` file exporting a JS object
186 The search will begin in the working directory and move up the
187 directory tree until a configuration file is found.
188
189 -f, --font-name
190
191 The font family name you want, default: "webfont".
192
193 -h, --help
194
195 Output usage information.
196
197 -v, --version
198
199 Output the version number.
200
201 -r, --formats
202
203 Only this formats generate.
204
205 -d, --dest
206
207 Destination for generated fonts.
208
209 -t, --template
210
211 Type of template ('css', 'scss') or path to custom template.
212
213 -s, --dest-template
214
215 Destination for generated template. If not passed used `dest` argument value.
216
217 -c, --template-class-name
218
219 Class name in css template.
220
221 -p, --template-font-path
222
223 Font path in css template.
224
225 -n, --template-font-name
226
227 Font name in css template.
228
229 --verbose
230
231 Tell me everything!.
232
233 For "svgicons2svgfont":
234
235 --font-id
236
237 The font id you want, default as "--font-name".
238
239 --font-style
240
241 The font style you want.
242
243 --font-weight
244
245 The font weight you want.
246
247 --fixed-width
248
249 Creates a monospace font of the width of the largest input icon.
250
251 --center-horizontally
252
253 Calculate the bounds of a glyph and center it horizontally.
254
255 --normalize
256
257 Normalize icons by scaling them to the height of the highest icon.
258
259 --font-height
260
261 The outputted font height [MAX(icons.height)].
262
263 --round
264
265 Setup the SVG path rounding [10e12].
266
267 --descent
268
269 The font descent [0].
270
271 --ascent
272
273 The font ascent [height - descent].
274
275 --start-unicode
276
277 The start unicode codepoint for unprefixed files [0xEA01].
278
279 --prepend-unicode
280
281 Prefix files with their automatically allocated unicode codepoint.
282
283 --metadata
284
285 Content of the metadata tag.
286```
287
288### Exit codes
289
290The CLI can exit the process with the following exit codes:
291
292* 0: All ok.
293* 1: Something unknown went wrong.
294* Other: related to using packages.
295
296## Related
297
298* [svgicons2svgfont](https://github.com/nfroidure/svgicons2svgfont) - Simple tool to merge multiple icons to an SVG font.
299* [svg2ttf](https://github.com/fontello/svg2ttf) - Converts SVG fonts to TTF format.
300* [ttf2eot](https://github.com/fontello/ttf2eot) - Converts TTF fonts to EOT format.
301* [ttf2woff](https://github.com/fontello/ttf2woff) - Converts TTF fonts to WOFF format.
302* [ttf2woff2](https://github.com/nfroidure/ttf2woff2) - Converts TTF fonts to WOFF2.
303
304## Roadmap
305
306* The ability to generate from any type to any type.
307* More tests, include CLI test.
308* Improved docs.
309* Reduce package size (maybe implement `ttf2woff2` with native js library).
310* Improve performance (maybe use cache for this).
311* Implement `webpack` loader.
312* Close all issues.
313
314## Contribution
315
316Feel free to push your code if you agree with publishing under the MIT license.
317
318## [Changelog](CHANGELOG.md)
319
320## [License](LICENSE)