How does gulp treat the Promise of a then()?

ぃ、小莉子 提交于 2019-12-11 15:57:56

问题


I have a strange behaviour using gulp as build tool. I got the following code from another question, which is meant for cleaning up build files before another run:

function clean() {
    var delResult = del(['build/**/*', 'dist/**/*']);
    return delResult.then(del(['build', 'dist']));
}

gulp.task('clean', clean);

Then I have my default task which includes the clean task in the rest of the build:

gulp.task('default', gulp.series('clean', gulp.parallel('doJsStuff, doCssStuff', 'doEvenMoreStuff'));

The problem is that gulp already continues with the build before the two del-operations have completed. As I understand it then will return a promise and gulp should continue when that promise gets fulfilled. Of course the then-promise can not get fulfilled before the first del-promise does. So I guess it should work as expected but doesn't.
The behaviour is the same in gulp 3 and 4.

I am aware that I can do the same stuff using only one del-call:

function clean() {
    return del(['build/**', 'dist/**']);
}

That actually works and is a solution for my problem. Still I would like to understand, why the chained promises don't work. Can anybody tell me?

来源:https://stackoverflow.com/questions/51404088/how-does-gulp-treat-the-promise-of-a-then

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!