P
P
pegas2018-09-16 21:55:46
JavaScript
pegas, 2018-09-16 21:55:46

How to make async in gulp thread?

Here is an example

gulp.src('style/*.css').pipe(minify()).dest('www/style')

Now, each file is processed in turn, but how can I make the files start processing at the same time?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
profesor08, 2018-09-16
@profesor08

Make an async function in which you get a list of files, create a promise for each file and minify it, then wait for all the promises to be fulfilled.
Well, do not forget to make a wrapper for it so that it can be passed to pipe.

A
Andrew, 2018-09-16
@allard

Do return gulp.src(....).
I will add to my comment: I understood why I had no doubts about asynchrony, I always wrote like this

return gulp.src(paths.files.src).pipe(........).pipe(gulp.dest(paths.build));

Doc:
https://github.com/gulpjs/gulp/blob/master/docs/AP...
gulp.src: Returns a stream of Vinyl files that can be piped to plugins.
At the output, we have a stream, which means it is an asynchronous process.
If you don't return anything (reutrn undefined;), then watcher and taxi will not understand that this is an asynchronous stream.
Hope it helps.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question