-
Notifications
You must be signed in to change notification settings - Fork 4
Terminology
A gulp task is a plain JavaScript function that returns promises, observables, child processes or streams, or call done()
callback when finished. Starting from gulp 4.0, a gulp task takes undefined
as context.
function gulpTask(done) {
assert(this === null);
// do things ...
done();
}
You register a gulp task using gulp.task()
method.
gulp.task(gulpTask);
And then run it in CLI.
$ gulp gulpTask
A configurable task has the same signature as normal gulp task, but be called with an object: { gulp, config, upstream }
as context.
// Note: You don't write configurable task but configuration.
// The plugin generates configurable task for you.
function configurableTask(done) {
done();
}
You don't write configurable tasks, instead, you create a configurable task by defining a configuration, and call chef()
function.
var gulp = require('gulp');
var chef = require('gulp-chef');
var meals = chef({
scripts: {
src: 'src/**/*.js',
dest: 'dist/'
}
});
gulp.registry(meals);
This generates a configurable task called "scripts
" for you. The chef()
function returns a gulp registry. You can access the "scripts
" configurable task via meals.get('scripts')
. But normally you call gulp.registry()
to register all available tasks in the registry.
gulp.registry(meals);
Once you call gulp.registry()
, you can run registered tasks in CLI.
$ gulp scripts
When invoked, the configurable task will be called with the configuration defined with it, some kind of like this:
scripts.call({
gulp: gulp,
config: {
src: 'src/**/*.js',
dest: 'dist/'
}
}, done);
Also note that in this example, the "scripts
" entry in the configuration is the module name of a recipe, that must be present in your project's "gulp
" folder, or of a plugin, that must be installed. Check out Writing Recipes and Using Plugins for more information.
A configurable recipe is, a configurable and reusable gulp task, that has the same signature as normal gulp task, but be called with an object: { gulp, config, upstream }
as context. A configurable recipe is the function you actually write and reuse. In fact, a "configurable task" is simply a wrapper that calls "configurable recipe" with exactly the same name.
function scripts(done) {
// Note: you have asscess to the gulp instance.
var gulp = this.gulp;
// Note: you can access configuration via 'config' property.
var config = this.config;
// do things ...
done();
}