gulp: where is the gulp task callback function defined?

落爺英雄遲暮 提交于 2019-12-02 23:43:41

The callback function comes from Orchestrator (or the new one -- undertaker -- in Gulp 4) and is actually nothing more than a call to tell the task system that your task is "done". That's why they changed it to

gulp.task('something', function(done) { ... });

In the upcoming docs to make that point clearer.

Why do you need the callback? Usually, you return a stream when defining a task:

gulp.task('goodstuff', function() {
    return gulp.src('./app/**/*.*')
        .pipe(someotherstuff())
        .pipe(gulp.dest('./dist');
});

By returning a stream, the task system is able to plan the execution of those streams. But sometimes, especially when you're in callback hell or calling some streamless plugin, you aren't able to return a stream. That's what the callback is for. To let the task system know that you're finished and to move on to the next call in the execution chain.

To your questions:

Is this the only functionality of the callback, to raise an exception if passed an argument and to complete successfully otherwise?

No, the only functionality is to let the task system know that your task is done.

Is there anything else that it does?

No.

Could I override it with some other function (and would there be any sane reason to do so)?

No and No.

Is it possible to pass any other arguments to a gulp task function?

No, but why would you? You have the full scope of a JS file on your service, just place your arguments somewhere around.

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