考虑这两个 gulp 任务:
gulp.task('src', function(done) {
gulp.src('docs/*')
.on('end', function() {
console.log('ending');
done();
});
});
gulp.task('dest', function(done) {
gulp.src('docs/*')
.pipe(gulp.dest('temp'))
.on('end', function() {
console.log('ending');
done();
});
});
Running gulp dest
行为如预期,输出:
[12:33:15] Using gulpfile ~/Projects/gulp-exit/gulpfile.js
[12:33:15] Starting 'dest'...
ending
[12:33:15] Finished 'dest' after 13 ms
然而,运行gulp src
仅输出:
[12:31:11] Using gulpfile gulpfile.js
[12:31:11] Starting 'src'...
The 'end'
回调永远不会被调用。经过一番调试后,我认为dest
任务是flowing而源任务中的流则不是。
发出信号src
通过调用显式地执行任务stream.resume()
:
gulp.task('src', function(done) {
gulp.src('docs/*')
.on('end', function() {
console.log('ending');
done();
})
.resume();
});
给出预期输出:
[12:46:52] Using gulpfile gulpfile.js
[12:46:52] Starting 'src'...
ending
[12:46:52] Finished 'src' after 11 ms
我在插件中看到过同样的行为组合:gulp.dest and 喝摩卡咖啡似乎又回到了流动的溪流吞咽记录器 and gulp-gh-页面 do not.
为什么行为上有差异?