Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including grunt-fontmin with all npm packages installed. Try it out:

var gruntFontmin = require("grunt-fontmin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

grunt-fontmin v0.1.2

grunt plugin to minimize Chinese font

grunt-fontmin

grunt plugin to minimize Chinese fonts

Configuration

grunt.initConfig({
  fontmin: {
    options: {
      dest:    'www-bin/fonts/',  // default './'
      basedir: 'fonts/'           // 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')

options (task-wide)

  • dest:
    • destination directory, include trailing slash
    • default: ./
  • basedir:
    • source font directory, include trailing slash
    • default: ./

target options

  • grunt's target name
    • relative to basedir, pattern of fonts to minimize
    • pass to grunt.file.expand()
  • src:
    • pattern of files, relative to Gruntfile
    • src's content is passed to getText, it returns characters to included in minimized font
  • 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)
  • css:
    • NOT IMPLEMENTED!!
    • this is planned for future, css with inlined base64 font

Caveat!

It's hard to include texts in css content:attr('')

Not formally tested, so it can be buggy

You can't change output filename

You are responsible to get proper license of fonts you minify!
or consider free fonts.

License

MIT (C) wacky6

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free