{"id":13459190,"url":"https://github.com/ecomfe/fontmin","last_synced_at":"2025-05-07T07:42:25.680Z","repository":{"id":28489176,"uuid":"32005403","full_name":"ecomfe/fontmin","owner":"ecomfe","description":"Minify font seamlessly","archived":false,"fork":false,"pushed_at":"2024-11-22T03:56:37.000Z","size":29631,"stargazers_count":5968,"open_issues_count":65,"forks_count":323,"subscribers_count":96,"default_branch":"master","last_synced_at":"2025-05-06T15:19:09.571Z","etag":null,"topics":["font","fontmin","icon-font","subset"],"latest_commit_sha":null,"homepage":"http://ecomfe.github.io/fontmin","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ecomfe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-03-11T08:01:49.000Z","updated_at":"2025-05-06T01:06:31.000Z","dependencies_parsed_at":"2022-07-12T16:09:21.525Z","dependency_job_id":"2c7c6f5b-ed8f-42f5-8958-3c5ddd09cf1f","html_url":"https://github.com/ecomfe/fontmin","commit_stats":{"total_commits":171,"total_committers":13,"mean_commits":"13.153846153846153","dds":0.368421052631579,"last_synced_commit":"87462e200d1feeb9e92e7a558c9bd3bf2f518132"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Ffontmin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Ffontmin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Ffontmin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ecomfe%2Ffontmin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ecomfe","download_url":"https://codeload.github.com/ecomfe/fontmin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252836724,"owners_count":21811769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["font","fontmin","icon-font","subset"],"created_at":"2024-07-31T09:01:09.397Z","updated_at":"2025-05-07T07:42:25.651Z","avatar_url":"https://github.com/ecomfe.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","JavaScript libs","Fonts"],"sub_categories":[],"readme":"\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://ecomfe.github.io/fontmin/\"\u003e\n        \u003cimg height=\"128\" width=\"128\" src=\"https://raw.githubusercontent.com/ecomfe/fontmin/master/fontmin.png\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n# fontmin\n**Minify font seamlessly**\n\n[![NPM version][npm-image]][npm-url]\n[![Build Status][travis-image]][travis-url]\n[![Downloads][downloads-image]][npm-url]\n[![Dependencies][dep-image]][dep-url]\n[![Font support][font-image]][font-url]\n\n## Homepage\n\n- [简体中文](http://ecomfe.github.io/fontmin/)\n- [繁體中文](http://ecomfe.github.io/fontmin/tw)\n- [日本語](http://ecomfe.github.io/fontmin/jp)\n- [한국어](http://ecomfe.github.io/fontmin/kr)\n- [English](http://ecomfe.github.io/fontmin/en)\n\n## Install\n\n```sh\n$ npm install --save fontmin\n```\n\n### Notice\n\n**fontmin v2.x only support ES Modules, and run on Node v16+.**\n\nIf you need to use CommonJS version, please install `fontmin v1.x`:\n\n\u003e npm install --save fontmin@1\n\n## Usage\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .src('fonts/*.ttf')\n    .dest('build/fonts');\n\nfontmin.run(function (err, files) {\n    if (err) {\n        throw err;\n    }\n\n    console.log(files[0]);\n    // =\u003e { contents: \u003cBuffer 00 01 00 ...\u003e }\n});\n```\n\nYou can use [gulp-rename](https://github.com/hparra/gulp-rename) to rename your files:\n\n```js\nimport Fontmin from 'fontmin';\nconst rename = require('gulp-rename');\n\nconst fontmin = new Fontmin()\n    .src('fonts/big.ttf')\n    .use(rename('small.ttf'));\n```\n\n## API\n\n### new Fontmin()\n\nCreates a new `Fontmin` instance.\n\n### .src(file)\n\nType: `Array|Buffer|String`\n\nSet the files to be optimized. Takes a buffer, glob string or an array of glob strings\nas argument.\n\n### .dest(folder)\n\nType: `String`\n\nSet the destination folder to where your files will be written. If you don't set\nany destination no files will be written.\n\n### .use(plugin)\n\nType: `Function`\n\nAdd a `plugin` to the middleware stack.\n\n### .run(cb)\n\nType: `Function`\n\nOptimize your files with the given settings.\n\n#### cb(err, files, stream)\n\nThe callback will return an array of vinyl files in `files` and a Readable/Writable\nstream in `stream`\n\n## Plugins\n\nThe following plugins are bundled with fontmin:\n\n* [glyph](#glyph) — Compress ttf by glyph.\n* [ttf2eot](#ttf2eot) — Convert ttf to eot.\n* [ttf2woff](#ttf2woff) — Convert ttf to woff.\n* [ttf2woff2](#ttf2woff2) — Convert ttf to woff2.\n* [ttf2svg](#ttf2svg) — Convert ttf to svg.\n* [css](#css) — Generate css from ttf, often used to make iconfont.\n* [svg2ttf](#svg2ttf) — Convert font format svg to ttf.\n* [svgs2ttf](#svgs2ttf) — Concat svg files to a ttf, just like css sprite.\n* [otf2ttf](#otf2ttf) — Convert otf to ttf.\n\n### .glyph()\n\nCompress ttf by glyph.\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .use(Fontmin.glyph({\n        text: '天地玄黄 宇宙洪荒',\n        hinting: false         // keep ttf hint info (fpgm, prep, cvt). default = true\n    }));\n```\n\n### .ttf2eot()\n\nConvert ttf to eot.\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .use(Fontmin.ttf2eot());\n```\n\n### .ttf2woff()\n\nConvert ttf to woff.\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .use(Fontmin.ttf2woff({\n        deflate: true           // deflate woff. default = false\n    }));\n```\n\n### .ttf2woff2()\n\nConvert ttf to woff2.\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .use(Fontmin.ttf2woff2());\n```\n\n### .ttf2svg()\n\nConvert ttf to svg.\n\nyou can use [imagemin-svgo](https://github.com/imagemin/imagemin-svgo) to compress svg:\n\n```js\nimport Fontmin from 'fontmin';\nconst svgo = require('imagemin-svgo');\n\nconst fontmin = new Fontmin()\n    .use(Fontmin.ttf2svg())\n    .use(svgo());\n\n```\n\n### .css()\n\nGenerate css from ttf, often used to make iconfont.\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .use(Fontmin.css({\n        fontPath: './',         // location of font file\n        base64: true,           // inject base64 data:application/x-font-ttf; (gzip font with css).\n                                // default = false\n        glyph: true,            // generate class for each glyph. default = false\n        iconPrefix: 'my-icon',  // class prefix, only work when glyph is `true`. default to \"icon\"\n        fontFamily: 'myfont',   // custom fontFamily, default to filename or get from analysed ttf file\n        asFileName: false,      // rewrite fontFamily as filename force. default = false\n        local: true             // boolean to add local font. default = false\n    }));\n```\n\nAlternatively, a transform function can be passed as `fontFamily` option.\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .use(Fontmin.css({\n        // ...\n        fontFamily: function(fontInfo, ttf) {\n          return \"Transformed Font Family Name\"\n        },\n        // ...\n    }));\n```\n\n### .svg2ttf()\n\nConvert font format svg to ttf.\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .src('font.svg')\n    .use(Fontmin.svg2ttf());\n```\n\n### .svgs2ttf()\n\nConcat svg files to a ttf, just like css sprite.\n\nawesome work with [css](#css) plugin:\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .src('svgs/*.svg')\n    .use(Fontmin.svgs2ttf('font.ttf', {fontName: 'iconfont'}))\n    .use(Fontmin.css({\n        glyph: true\n    }));\n```\n\n### .otf2ttf()\n\nConvert otf to ttf.\n\n```js\nimport Fontmin from 'fontmin';\n\nconst fontmin = new Fontmin()\n    .src('fonts/*.otf')\n    .use(Fontmin.otf2ttf());\n```\n\n## CLI\n\n```bash\n$ npm install -g fontmin\n```\n\n```sh\n$ fontmin --help\n\n  Usage\n    $ fontmin \u003cfile\u003e [\u003coutput\u003e]\n    $ fontmin \u003cdirectory\u003e [\u003coutput\u003e]\n    $ fontmin \u003cfile\u003e \u003e \u003coutput\u003e\n    $ cat \u003cfile\u003e | fontmin \u003e \u003coutput\u003e\n\n  Example\n    $ fontmin fonts/* build\n    $ fontmin fonts build\n    $ fontmin foo.ttf \u003e foo-optimized.ttf\n    $ cat foo.ttf | fontmin \u003e foo-optimized.ttf\n\n  Options\n    -t, --text                          require glyphs by text\n    -b, --basic-text                    require glyphs with base chars\n    -d, --deflate-woff                  deflate woff\n    --font-family                       font-family for @font-face CSS\n    --css-glyph                         generate class for each glyf. default = false\n    -T, --show-time                     show time fontmin cost\n```\n\nyou can use `curl` to generate font for websites running on PHP, ASP, Rails and more:\n\n```sh\n$ text=`curl www.baidu.com` \u0026\u0026 fontmin -t \"$text\" font.ttf\n```\nor you can use [html-to-text](https://www.npmjs.com/package/html-to-text) to make it smaller:\n\n```sh\n$ npm install -g html-to-text\n$ text=`curl www.baidu.com | html-to-text` \u0026\u0026 fontmin -t \"$text\" font.ttf\n```\n\nwhat is more, you can use [phantom-fetch-cli](https://www.npmjs.com/package/phantom-fetch-cli) to generate font for `SPA` running JS template:\n\n```sh\n$ npm install -g phantom-fetch-cli\n$ text=`phantom-fetch http://www.chinaw3c.org` \u0026\u0026 fontmin -t \"$text\" font.ttf\n```\n\n## Related\n\n- [fontmin-app](https://github.com/ecomfe/fontmin-app)\n- [gulp-fontmin](https://github.com/ecomfe/gulp-fontmin)\n- [fonteditor](https://github.com/ecomfe/fonteditor)\n\n## Thanks\n\n- [imagemin](https://github.com/imagemin/imagemin)\n- [free chinese font](http://zenozeng.github.io/Free-Chinese-Fonts/)\n- [浙江民间书刻体][font-url]\n\n## License\n\nMIT © [fontmin](https://raw.githubusercontent.com/ecomfe/fontmin/master/LICENSE)\n\n\n[downloads-image]: http://img.shields.io/npm/dm/fontmin.svg\n[npm-url]: https://npmjs.org/package/fontmin\n[npm-image]: http://img.shields.io/npm/v/fontmin.svg\n\n[travis-url]: https://travis-ci.org/ecomfe/fontmin\n[travis-image]: http://img.shields.io/travis/ecomfe/fontmin.svg\n\n[dep-url]: https://david-dm.org/ecomfe/fontmin\n[dep-image]: http://img.shields.io/david/ecomfe/fontmin.svg\n\n[font-image]: https://img.shields.io/badge/font-eonway-blue.svg\n[font-url]: http://weibo.com/eonway\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Ffontmin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fecomfe%2Ffontmin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fecomfe%2Ffontmin/lists"}