Subset Fonts Maker
grunt plugin to minimize CJK fonts
- Deleted css output
- You should write @font-face in your css by yourself
- Added woff2 output
- By using ttf2woff2
- It requires node-gyp to build itself
- Added Japanese readme
ttf, ttc, otf, woff, woff2
ttf, woff, woff2
-
npm install grunt-fontmin-ex --save-dev
- Add configuration in Gruntfile.js
grunt.initConfig({
fontmin: {
options: {
dest: 'www-bin/fonts/', // default './'
basedir: 'fonts/' // default './'
types: ['ttf','woff','woff2'] // default
},
'{Source-hans*.otf}': {
/* getText: (html) => string_of_characters_to_include
* if not specified, use html-to-text
*/
getText: getBody,
src: 'www-bin/**/*.html'
},
'cn-cursive.ttf': {
getText: getHeadings,
src: 'www-bin/**/*.html'
}
}
})
grunt.loadNpmTasks('grunt-fontmin')
- dest:
- destination directory, include trailing slash
- default:
./
- basedir:
- source font directory, include trailing slash
- default:
./
- types:
-
*Array*
. - output extention(s)
- 'ttf', 'woff', 'woff2' are supported.
-
- grunt's target name
- relative to
basedir
, pattern of fonts to minimize - pass to
grunt.file.expand()
- relative to
- src:
- pattern of files, relative to
Gruntfile
- src's content is passed to getText, it returns characters to included in minimized font
- pattern of files, relative to
- getText:
- filter function: (htmlContent) => string_of_chars_to_include
- if not provided, use builtin
html-to-text
- you can write your own
- woff:
- output compressed woff, anything other than
undefined
- default if no other output option is provided (like
css
)
- output compressed woff, anything other than
You can't change output filename
You are responsible to get proper license of fonts you minify!
or consider free fonts
MIT (C) wacky6 MIT (C) tamaina