1

I'm trying to setup a Gulp task to convert .ttf fonts to webfont formats, by using gulp-ttf2woff and gulp-ttf2woff2 plugins. The respectively convert the source fonts to .woff and .woff2.

I've come out with these two separate functions, one for each plugin:

function fontsW(done) {
    src(fontsSrc)
        .pipe(ttf2woff())
        .pipe(dest(fontsDist))
    done();
};

function fontsW2(done) {
    src(fontsSrc)
        .pipe(ttf2woff2())
        .pipe(dest(fontsDist))
    done();
};

Is it possible to condensate them in a single function, let's call it function fonts(done) {} that takes care of both plugins at once?

Basically, I'd like to have something like this

function fontsW2(done) {
    src(fontsSrc)
        .pipe(ttf2woff())
        .pipe(ttf2woff2())
        .pipe(dest(fontsDist))
    done();
};

where both ttf2woff() and ttf2woff2() receive the output of src and give their own processed files to dest.

Sekhemty
  • 1,222
  • 2
  • 13
  • 33

2 Answers2

2

You can do this:

function fontsW(done) {
    src(fontsSrc)
        .pipe(ttf2woff())
        .pipe(dest(fontsDist))

     src(fontsSrc)
        .pipe(ttf2woff2())
        .pipe(dest(fontsDist))
    done();
};
Mark
  • 143,421
  • 24
  • 428
  • 436
0

You can define a task that calls both functions in parallel:

gulp.task('fonts', gulp.parallel(ttf2woff, ttf2woff2));

You can either use this task in other tasks (e.g. call it from your default task), or you can call it directly from terminal:

gulp fonts
Amir
  • 1,885
  • 3
  • 19
  • 36
  • Thank you, I know that I can call multiple functions from a single task, but my question was about creating a single function on the first place – Sekhemty Mar 17 '19 at 11:32