Skip to content

iagurban/gulp-gfonts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gulp-gfonts Build Status codecov

A gulp plugin for smart downloading fonts from Google Fonts© and generating CSS for/with them

Usage

  1. Install gulp-gfonts (as a development dependency in most cases):
npm install --save-dev gulp-fonts
  1. Create json-file with definitions for needed fonts:
{ "Roboto": ["300", "300i", "500", "800"] }

or

{ "Open Sans": "300,300i,500,500i,800,800i" }

or just copy url's query from Google Fonts constructor

family=Roboto:500,100i|Open+Sans:100
  1. Then in gulpfile.js:

Use all avalilible formats

var gfonts = require('gulp-gfonts');

gulp.task('fonts', function () {
  gulp.src('fonts.json')
    .pipe(gfonts())
    .pipe(gulp.dest('./dist')); // => ./dist/fonts.css, ./dist/*.woff, ./dist/*.eot, etc.
});

Pack woff2 fonts to css-file

gulp.task('fonts', function () {
  gulp.src('fonts.json')
    .pipe(gfonts({
      embed: true,
      formats: ['woff2']
    }))
    .pipe(gulp.dest('./dist')); // => ./dist/fonts.css
});

Pack fonts to css-file, download eot for <ie9 separately, concat css

gulp.task('fonts', function () {
  s =
    gulp.src('fonts.json')
    .pipe(gfonts({
      inCssBase: './fonts', // to be served like domain.com/fonts/blahblah.eot
      embed: true
    }))
    .pipe(gulpHydra({
      css: (f) => /.*\.css$/.test(f.path),
      fonts: (f) => !(/.*\.css$/.test(f.path))
    }));

  s.fonts.pipe(gulp.dest('./static/fonts')); // => ./static/fonts/*.eot

  merge2(
    gulp.src('./app.styl').pipe(gulpStylus()),
    s.css
  )
  .pipe(gulpConcat('index.css'))
  .pipe(gulp.dest('./static')); // => ./static/index.css
});

About

A gulp plugin for smart downloading fonts from Google Fonts© and generating CSS for them

Resources

License

Stars

Watchers

Forks

Packages

No packages published