Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fontgen-loader

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fontgen-loader

A WebPack loader to automaticaly generate font files and CSS to make your own icon font

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
67
decreased by-12.99%
Maintainers
1
Weekly downloads
 
Created
Source

fontgen-loader - Bam, easy webfonts!

Have you faced this? You have 4 icons from FontAwesome, and 19 from Glyphicons, and maybe you are eying at another webfont's icons and wishing to use them?

What a mess! Okay okay, so what do we do? We make our own. And how? ...good question. In fact, this question comes up just so often... So I decided to write a little thing to help out.

How fontgen-loader works.

There is a tool that lets us generate fonts automaticaly by a configuration. The font is created by putting several SVG icons together and generating the proper file(s). That includes:

  • A font file for WOF, EOT, TTF and WOFF2. Also SVG, if you want. But there is a trend of removal withinb rowsers - you can see more on caniuse.
  • A CSS has your font configured. That means, it's a proper @font-face declaration inclusive icon classes.
  • If you want, a HTML demo page.

In order to use this loader, you need to be aware that this is a "trigger loader". That means, it can not just be added to your webpack.config.js like any other loader, you need to be aware of what it does in the long run.

configuration

module.exports = {
    resolve: {
        loaders: [
            {
                test: /\.font.(js|json)$/,
                loader: "style?css?fontgen?formats=woff,eot,ttf"
            }
        ]
    }
}

This loader returns CSS. Therefore, you have to pipe it through the proper loaders. You should be able to use this with the extract-text-plugin as well.

However, there are more configurations. you could also specify a custom template to use, to return different kinds of source. A LESS or SCSS version, for instance? Up to you.

Usage

Now that we have the loader configured, it's about time we give this a go. First, you want to load your font like so, within your entry code:

// main.js
require("./Awesomecons.font"); // .js or .json does not matter if you used the config above.

Now, the loader will load in the font from the given configuration, and the CSS is added to your webpack project, properly rendered and prepared. Now, this is what a configuration should look like. The following is an example, and I am using JSON here, since I know that my code is more static, but you may have a varying requirement, which is why JS will be allowed. Make sure the configuration ends up being the contents of module.exports.

Example:

{
    "files": [
        "icon/my.svg",
        "icon/awesome.svg",
        "icon/stuff.svg"
    ],
    "fontName": "Awesomecons",
    "classPrefix": "ai-",
    "baseClass": "ai",
    "fixedWidth": true
}

Now, the loader will pick up this config, pull it through the generator and:

  • Generate CSS with the base and class prefix.
  • Font files for the three SVG icons.

And there you are - your webfont is done. Now, here is one thing: You can use JavaScript too. A useful thing is, that there are two additional options that I did not mention:

  • .rename: This should be a function that returns the icon's name based on the input (filename).
  • .log: You can log stuff here.

You also can use a module like glob to pick up a variable set of icons, too. Mix and match and mind the various licenses - and make your own webfont!

Configuration

Loader parameters

  • formats, Array Possible values are: ["svg", "eot", "wof", "ttf"].

  • template, String Which template to use? By default, a CSS one is used. The template is to be processed by Handlebars. See the generator's readme itself for more info.

Font configuration (*.font.js or *.font.json)

  • files, Array An array of SVG icon files.

  • ´fontName`, String Name of your font.

  • classPrefix, String The prefix to be used with each icon class.

  • baseClass, String The base class, under which each icon class is to be crated.

For additional options, see the generator's README file.

Keywords

FAQs

Package last updated on 29 Jun 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc