Reputation: 123
I use Gulp 4 and I have this task:
gulp.task('deploy', gulp.series('clean', 'handlers:all', 'deployment'));
The task call three other tasks:
clean
: removes the build folder.handlers:all
: re-creates the build folder and adds files there.deployment
: transfers the contents of the build folder to another locationI have a problem with task the deployment
which look something like this:
gulp.task('deployment', done => {
gulp.src('./build/')
.pipe(gulp.dest('../other-project/'));
});
gulp.src() can't find the build folder because it was deleted by the task clean
. When I set the timeout there are no problems. But this solution is bad.
gulp.task('deployment', done => {
setTimeout(() => {
gulp.src('./build/')
.pipe(gulp.dest('../other-project/'));
}, 2000);
});
How do I solve this problem?
Task clean
:
gulp.task('clean', done => {
del('./build/');
done();
});
Task handlers:all
:
gulp.task('handlers:all', gulp.parallel('scripts', 'templates', 'styles', 'fonts', 'favicons', 'images', 'svg', 'dist'));
Upvotes: 2
Views: 63
Reputation: 7973
Try to replace your clean
task to the next one:
gulp.task('clean', done => {
del('./build/').then(() => done());
});
It needs because of del
package returns a promise and you should tell gulp to wait till it will be resolved. The other option can be del.sync
.
I'm not sure about rest of tasks but it should follow the same process. If you have any async tasks - call done
in the right place.
It might be useful for you async vs sync
Hope it makes sense.
Upvotes: 1