mirror of
https://github.com/ecomfe/fontmin.git
synced 2026-01-18 14:26:45 +00:00
fontmin 
Minify font seamlessly
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 ...> }
});
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.
- ttf2eot — Convert ttf to eot.
- ttf2woff — Convert ttf to woff.
- ttf2svg — Convert ttf to svg.
.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
}));
.ttf2svg()
Convert ttf to svg.
var Fontmin = require('fontmin');
var fontmin = new Fontmin()
.use(Fontmin.ttf2svg({
clone: true
}));
Thx
Languages
JavaScript
92.9%
TypeScript
3.6%
Smarty
2.1%
HTML
1.4%