Gulp 4: Run dependency task a single time
See original GitHub issueI have a gulpfile created that runs multiple tasks on build, but needs to run a clean task before everything. I would like to define the clean as a dependency of the tasks themselves, and not have to define it in the default
dependencies.
This is my grunt file:
var gulp = require('gulp');
// Not all tasks need to use streams
var gulp = require('gulp');
// Not all tasks need to use streams
gulp.task('clean', function(cb) {
setTimeout(function() {
console.log('cleaning done');
cb();
}, 500);
});
gulp.task('scripts', gulp.series('clean', function(cb) {
setTimeout(function() {
console.log('scripts done');
cb();
}, 500);
}));
gulp.task('images', gulp.series('clean', function(cb) {
setTimeout(function() {
console.log('images done');
cb();
}, 500);
}));
gulp.task('default', gulp.parallel('scripts', 'images'));
Which outputs:
[11:25:11] Using gulpfile C:\Projects\gulp-playground\gulpfile.js
[11:25:11] Starting 'default'...
[11:25:11] Starting 'scripts'...
[11:25:11] Starting 'images'...
[11:25:11] Starting 'clean'...
[11:25:11] Starting 'clean'...
cleaning done
[11:25:11] Finished 'clean' after 503 ms
[11:25:11] Starting '<anonymous>'...
cleaning done
[11:25:11] Finished 'clean' after 504 ms
[11:25:11] Starting '<anonymous>'...
scripts done
[11:25:12] Finished '<anonymous>' after 501 ms
[11:25:12] Finished 'scripts' after 1.01 s
images done
[11:25:12] Finished '<anonymous>' after 502 ms
[11:25:12] Finished 'images' after 1.01 s
[11:25:12] Finished 'default' after 1.01 s
However my desired output is this:
[11:26:57] Using gulpfile C:\Projects\gulp-playground\gulpfile.js
[11:26:57] Starting 'default'...
[11:26:57] Starting 'clean'...
[11:26:57] Starting 'scripts'...
[11:26:57] Starting 'images'...
cleaning done
[11:26:57] Finished 'clean' after 503 ms
scripts done
[11:26:57] Finished 'scripts' after 505 ms
images done
[11:26:57] Finished 'images' after 505 ms
[11:26:57] Finished 'default' after 507 ms
I can get that by changing my gulpfile to this:
var gulp = require('gulp');
// Not all tasks need to use streams
gulp.task('clean', function(cb) {
setTimeout(function() {
console.log('cleaning done');
cb();
}, 500);
});
gulp.task('scripts', function(cb) {
setTimeout(function() {
console.log('scripts done');
cb();
}, 500);
});
gulp.task('images', function(cb) {
setTimeout(function() {
console.log('images done');
cb();
}, 500);
});
gulp.task('default', gulp.parallel('clean', 'scripts', 'images'));
However as a gulpfile grows in size and complexity, managing the dependency graph gets painfull and difficult. Is there any better way of doing this?
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to run Gulp tasks sequentially one after the other
By default, gulp runs tasks simultaneously, unless they have explicit dependencies. This isn't very useful for tasks like clean , where you don't...
Read more >The new task execution system - gulp.parallel and gulp.series
Reading time: 7 minutes. More on Gulp, Tools. One of the major changes in Gulp 4 is the new task execution system. In...
Read more >How to run Gulp tasks sequentially one after the other - Edureka
By default, gulp runs tasks simultaneously, unless they have explicit dependencies. This isn't very useful for tasks like clean, ...
Read more >Task Dependencies in Gulp - Medium
What is known as 'task dependency' is one of the most troubling concepts to master when first learning GulpJS. Right off the bat,...
Read more >How to run gulp tasks synchronously - Talking Dotnet
Whenever any js file changes, watch task will run build-script task. As build-script task has dependency on clean task, so it will wait...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, the gulp.series/parallel paradigm is what we are going with. I spent around 1-2 months with just the concept. This stems from people having a hard time with the calculated dependency graph and gives users much more flexibility. We have added a very good
--tasks
CLI flag that prints your dependency graph to easy the complexity of managing the graph.Bam, there we go. Thats perfect. Thanks again.