How to run two separate plugins in parallel in a Gulp pipe?

173 views Asked by At

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.

2

There are 2 answers

0
Mark On BEST ANSWER

You can do this:

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

     src(fontsSrc)
        .pipe(ttf2woff2())
        .pipe(dest(fontsDist))
    done();
};
1
Amir On

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