Home

Awesome

webfont

NPM version Travis Build Status Build status

Generator of fonts from SVG icons.

Features

Table Of Contents


Installation

npm install --save-dev webfont

Usage

import webfont from "webfont";

webfont({
  files: "src/svg-icons/**/*.svg",
  fontName: "my-font-name",
})
  .then((result) => {
    // Do something with result
    Function.prototype(result);
    // Or return it
    return result;
  })
  .catch((error) => {
    throw error;
  });

or

const webfont = require("webfont").default;

webfont({
  files: "src/svg-icons/**/*.svg",
  fontName: "my-font-name",
})
  .then((result) => {
    // Do something with result
    Function.prototype(result);
    // Or return it
    return result;
  })
  .catch((error) => {
    throw error;
  });

Options

files

configFile

fontName

formats

template

templateClassName

templateFontPath

templateFontName

ligatures

glyphTransformFn

sort


svgicons2svgfont

svgicons2svgfont options

These can be appended to webfont options. These are passed directly to svgicons2svgfont.

svgicons2svgfont.fontName

svgicons2svgfont.fontId

svgicons2svgfont.fontStyle

svgicons2svgfont.fontWeight

svgicons2svgfont.fixedWidth

svgicons2svgfont.centerHorizontally

svgicons2svgfont.normalize

svgicons2svgfont.fontHeight

svgicons2svgfont.round

svgicons2svgfont.descent

svgicons2svgfont.ascent

svgicons2svgfont.metadata

svgicons2svgfont.log


Command Line Interface

The interface for command-line usage is fairly simplistic at this stage, as seen in the following usage section.

CLI Installation

Add the cli script to your package.json file's scripts object:

{
  "scripts": {
    "webfont": "node node_modules/webfont/dist/cli.js"
  }
}

If you're using cross-env:

{
  "scripts": {
    "webfont": "cross-env node_modules/webfont/dist/cli.js"
  }
}

CLI Usage

    Usage: webfont [input] [options]

    Input: File(s) or glob(s).

        If an input argument is wrapped in quotation marks, it will be passed to "fast-glob"
        for cross-platform glob support.

    Options:

        --config

            Path to a specific configuration file (JSON, YAML, or CommonJS)
            or the name of a module in \`node_modules\` that points to one.
            If no \`--config\` argument is provided, webfont will search for
            configuration  files in the following places, in this order:
               - a \`webfont\` property in \`package.json\`
               - a \`.webfontrc\` file (with or without filename extension:
                   \`.json\`, \`.yaml\`, and \`.js\` are available)
               - a \`webfont.config.js\` file exporting a JS object
            The search will begin in the working directory and move up the
            directory tree until a configuration file is found.

        -f, --font-name

            The font family name you want, default: "webfont".

        -h, --help

            Output usage information.

        -v, --version

            Output the version number.

        -r, --formats

            Only this formats generate.

        -d, --dest

            Destination for generated fonts.

        -m, --dest-create
            Create destination directory if it does not exist.

        -t, --template

            Type of template (\`css\`, \`scss\`, \`styl\`) or path to custom template.
'
        -s, --dest-template

            Destination for generated template. If not passed used \`dest\` argument value.

        -c, --template-class-name

            Class name in css template.

        -p, --template-font-path

            Font path in css template.

        -n, --template-font-name

            Font name in css template.

        --no-sort

            Keeps the files in the same order of entry

        --verbose

            Tell me everything!.

    For "svgicons2svgfont":

        --font-id

            The font id you want, default as "--font-name".

        --font-style

            The font style you want.

        --font-weight

            The font weight you want.

        --fixed-width

            Creates a monospace font of the width of the largest input icon.

        --center-horizontally

            Calculate the bounds of a glyph and center it horizontally.

        --normalize

            Normalize icons by scaling them to the height of the highest icon.

        --font-height

            The outputted font height [MAX(icons.height)].

        --round

            Setup the SVG path rounding [10e12].

        --descent

            The font descent [0].

        --ascent

            The font ascent [height - descent].

        --start-unicode

            The start unicode codepoint for files without prefix [0xEA01].

        --prepend-unicode

            Prefix files with their automatically allocated unicode codepoint.

        --metadata

            Content of the metadata tag.

        --add-hash-in-font-url

            Generated font url will be : [webfont].[ext]?v=[hash]

CLI Exit Codes

The CLI can exit the process with the following exit codes:


Related

Roadmap

Contribution

Feel free to push your code if you agree with publishing under the MIT license.

Changelog

Check our Changelog

License

Check our License