import Fontmin from 'fontmin';
const svgo = require('imagemin-svgo');
const fontmin = new Fontmin()
.use(Fontmin.ttf2svg())
.use(svgo());
.css()
Generate css from ttf, often used to make iconfont.
import Fontmin from 'fontmin';
const fontmin = new Fontmin()
.use(Fontmin.css({
fontPath: './', // location of font file
base64: true, // inject base64 data:application/x-font-ttf; (gzip font with css).
// default = false
glyph: true, // generate class for each glyph. default = false
iconPrefix: 'my-icon', // class prefix, only work when glyph is `true`. default to "icon"
fontFamily: 'myfont', // custom fontFamily, default to filename or get from analysed ttf file
asFileName: false, // rewrite fontFamily as filename force. default = false
local: true // boolean to add local font. default = false
}));
Alternatively, a transform function can be passed as fontFamily option.
import Fontmin from 'fontmin';
const fontmin = new Fontmin()
.use(Fontmin.css({
// ...
fontFamily: function(fontInfo, ttf) {
return "Transformed Font Family Name"
},
// ...
}));
.svg2ttf()
Convert font format svg to ttf.
import Fontmin from 'fontmin';
const fontmin = new Fontmin()
.src('font.svg')
.use(Fontmin.svg2ttf());
fontmin
Minify font seamlessly
Homepage
Install
Notice
fontmin v2.x only support ES Modules, and run on Node v16+.
If you need to use CommonJS version, please install
fontmin v1.x:Usage
You can use gulp-rename to rename your files:
API
new Fontmin()
Creates a new
Fontmininstance..src(file)
Type:
Array|Buffer|StringSet the files to be optimized. Takes a buffer, glob string or an array of glob strings as argument.
.dest(folder)
Type:
StringSet 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:
FunctionAdd a
pluginto the middleware stack..run(cb)
Type:
FunctionOptimize your files with the given settings.
cb(err, files, stream)
The callback will return an array of vinyl files in
filesand a Readable/Writable stream instreamPlugins
The following plugins are bundled with fontmin:
.glyph()
Compress ttf by glyph.
.ttf2eot()
Convert ttf to eot.
.ttf2woff()
Convert ttf to woff.
.ttf2woff2()
Convert ttf to woff2.
.ttf2svg()
Convert ttf to svg.
you can use imagemin-svgo to compress svg:
.css()
Generate css from ttf, often used to make iconfont.
Alternatively, a transform function can be passed as
fontFamilyoption..svg2ttf()
Convert font format svg to ttf.
.svgs2ttf()
Concat svg files to a ttf, just like css sprite.
awesome work with css plugin:
.otf2ttf()
Convert otf to ttf.
CLI
you can use
curlto generate font for websites running on PHP, ASP, Rails and more:or you can use html-to-text to make it smaller:
what is more, you can use phantom-fetch-cli to generate font for
SPArunning JS template:Related
Thanks
License
MIT © fontmin