2015-03-25 20:51:12 +08:00
2015-02-05 23:14:43 +08:00
2015-02-12 15:19:54 +08:00
2015-03-13 13:43:14 +08:00
2015-02-12 15:19:54 +08:00
2015-01-30 11:57:45 +08:00
2015-01-30 13:11:51 +08:00
2015-02-15 21:39:38 +08:00
2015-02-13 13:41:16 +08:00
2015-03-25 20:51:12 +08:00
2015-02-13 13:06:34 +08:00
2015-02-13 14:02:59 +08:00
2015-01-30 12:28:54 +08:00
2015-03-13 13:44:11 +08:00
2015-03-13 13:43:14 +08:00
2015-02-13 11:48:48 +08:00

fontmin

Minify font seamlessly

NPM version Build Status Downloads Dependencies Font support

Install

$ npm install --save fontmin

Usage

var Fontmin = require('fontmin');

var fontmin = new Fontmin()
    .src('fonts/*.ttf')
    .dest('build/fonts')

fontmin.run(function (err, files) {
    if (err) {
        throw err;
    }

    console.log(files[0]);
    // => { contents: <Buffer 00 01 00 ...> }
});

You can use gulp-rename to rename your files:

var Fontmin = require('Fontmin');
var rename = require('gulp-rename');

var fontmin = new Fontmin()
    .src('fonts/big.ttf')
    .use(rename('small.ttf'));

API

new Fontmin()

Creates a new Fontmin instance.

.src(file)

Type: Array|Buffer|String

Set the files to be optimized. Takes a buffer, glob string or an array of glob strings as argument.

.dest(folder)

Type: String

Set the destination folder to where your files will be written. If you don't set any destination no files will be written.

.use(plugin)

Type: Function

Add a plugin to the middleware stack.

.run(cb)

Type: Function

Optimize your files with the given settings.

cb(err, files, stream)

The callback will return an array of vinyl files in files and a Readable/Writable stream in stream

Plugins

The following plugins are bundled with fontmin:

.glyph()

Compress ttf by glyph.

var Fontmin = require('fontmin');

var fontmin = new Fontmin()
    .use(Fontmin.glyph({ 
        text: '天地玄黄 宇宙洪荒'
    }));

.ttf2eot()

Convert ttf to eot.

var Fontmin = require('fontmin');

var fontmin = new Fontmin()
    .use(Fontmin.ttf2eot({ 
        clone: true
    }));

.ttf2woff()

Convert ttf to woff.

var Fontmin = require('fontmin');

var fontmin = new Fontmin()
    .use(Fontmin.ttf2woff({ 
        clone: true,
        deflate: true          // deflate woff. default = false
    }));

.ttf2svg()

Convert ttf to svg.

you can use imagemin-svgo to compress svg:

var Fontmin = require('fontmin');
var svgo = require('imagemin-svgo');

var fontmin = new Fontmin()
    .use(Fontmin.ttf2svg({ 
        clone: true
    }));
    .use(svgo());

CLI

$ npm install -g fontmin
$ fontmin --help

  Usage
    $ fontmin <file> <directory>
    $ fontmin <directory> <output>
    $ fontmin <file> > <output>
    $ cat <file> | fontmin > <output>

  Example
    $ fontmin fonts/* build
    $ fontmin fonts build
    $ fontmin foo.ttf > foo-optimized.ttf
    $ cat foo.ttf | fontmin > foo-optimized.ttf

  Options
    -t, --text                          require glyphs by text
    -b, --basic-text                    require glyphs with base chars
    -d, --deflate-woff                  deflate woff
    -f, --font-family                   font-family for @font-face CSS
    -T, --show-time                     show time fontmin cost

you can use curl to generate font for websites running on PHP, ASP, Rails and more:

$ text=`curl www.baidu.com` && fontmin -t $text font.ttf

or you can use html-to-text to make it smaller:

$ npm install -g html-to-text
$ text=`curl www.baidu.com | html-to-text` && fontmin -t $text font.ttf

what is more, you can use phantom-fetch-cli to generate font for SPA running JS template:

$ npm install -g phantom-fetch-cli
$ text=`phantom-fetch http://www.chinaw3c.org` && fontmin -t $text font.ttf

Thanks

License

MIT © fontmin

Description
Minify font seamlessly
Readme MIT 29 MiB
Languages
JavaScript 92.9%
TypeScript 3.6%
Smarty 2.1%
HTML 1.4%