Based on fontmin
yarn add webfont-subset
npx webfont-subset # for help
Commands:
npx webfont-subset subset --help
Usage: webfont-subset subset [options]
Reduce fonts to specified subsets
Options:
-i, --input <string...> Source files, supports globing
-o, --output <string> Destination directory
-f, --format <string...> Additional output formats, besides ttf, available options: woff, woff2, eot, svg, css
-s, --subset <string...> Target subsets
-h, --help display help for command
npx webfont-subset text --help
Usage: webfont-subset text [options]
Reduce fonts to meet chars in text
Options:
-i, --input <string...> Source files, supports globing
-o, --output string Destination directory
-f, --format <string...> Additional output formats, besides ttf, available options: woff, woff2, eot, svg, css
-t, --text string Target text: use an argument or pipe in
-h, --html Treat input as html: will clear out tags and extract text
--help display help for command
Example:
npx webfont-subset subset -s english -i ./src/fonts/* -o ./dist/fonts
To use programmatically:
const {reduceText, reduceSubsets} = require('webfont-subset')
await reduceText(inputFonts, output, text, formats)
await reduceSubsets(inputFonts, output, subsets, formats)
npm i -g webfont-subset
webfont-subset subset -s english -i ./src/fonts/* -o ./dist/fonts
See available subsets in subsets.json