0.0.11 • Published 5 years ago

@unic/estatico-font-datauri v0.0.11

Weekly downloads
125
License
Apache-2.0
Repository
github
Last release
5 years ago

@unic/estatico-font-datauri

Uses gulp-simplefont64 to inline font files into base64-encoded data URIs

Installation

$ npm install --save-dev @unic/estatico-font-datauri

Usage

const gulp = require('gulp');
const env = require('minimist')(process.argv.slice(2));

/**
 * CSS font inlining task
 * Uses `gulp-simplefont64` to inline font files into base64-encoded data URIs
 *
 * Using `--watch` (or manually setting `env` to `{ watch: true }`) starts file watcher
 * When combined with `--skipBuild`, the task will not run immediately but only after changes
 */
gulp.task('css:fonts', () => {
  const task = require('@unic/estatico-font-datauri');

  const instance = task({
    src: [
      './src/assets/fonts/**/*',
    ],
    dest: './src/assets/.tmp',
    plugins: {
      concat: 'fonts.scss',
    },
    watch: {
      src: [
        './src/assets/fonts/**/*',
      ],
      name: 'css:fonts',
    },
  }, env);
  
  // Don't immediately run task when skipping build
  if (env.watch && env.skipBuild) {
    return instance;
  }

  return instance();
});

Run task (assuming the project's package.json specifies "scripts": { "gulp": "gulp" }): $ npm run gulp css:fonts

See possible flags specified above.

API

plugin(options, env) => taskFn

options

src (required)

Type: Object Default: null

Each property is passed to gulp.src, the key is used for the generated sprite's name.

dest (required)

Type: String Default: null

Passed to gulp.dest.

watch

Type: Object Default: null

Passed to file watcher when --watch is used.

plugins

Type: Object

plugins.concat (required)

Type: String Default: null

Passed to gulp-concat.

plugins.rename

Type: Function Default: null

Result will be assigned to file.path before passing the file to gulp-simplefont64. This allows you to optionally generate file names which can be handled by the plugin (e.g. FontFamily-FontStyle).

logger

Type: { info: Function, debug: Function, error: Function } Default: Instance of estatico-utils's Logger utility.

Set of logger utility functions used within the task.

env

Type: Object Default: {}

Result from parsing CLI arguments via minimist, e.g. { dev: true, watch: true }. Some defaults are affected by this, see above.

License

Apache 2.0.