Does anyone have a solution for automatically running 'subtasks' in gulp?
I'm new to gulp, and currently structure my gulp file like this:
gulp.task('build:ccss', function(cb) {
...
}
gulp.task('build:js', function(cb) {
...
}
gulp.task('build:img', function(cb) {
...
}
gulp.task('build:index', function(cb) {
...
}
And then I explicitly define the base task and have it execute the subtasks:
gulp.task('build', ['build:scss', 'build:js', 'build:img', 'build:index']);
I use this structure for several 'groups' of tasks: cleaning, building, linting.
I'm curious if someone has a solution for automatically executing subtasks when the base task is run, without creating an explicit definition as I have.
You could use async (or some other control flow library) this way:
var async = require('async');
gulp.task('build', function (callback) {
async.series([
function (cb) {
// example usage should be your build:scss task,
// notice the call of `cb` on end event
gulp.src('package.json')
.pipe(gulp.dest('test/'))
.on('end', cb);
},
function (cb) {
// same thing with the content of your build:js
},
// all your other tasks
], callback);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With