问题
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