I have two tasks. They have a common task which should be executed before the tasks.
With Gulp 3 I implement them this way:
gulp.task('compile', () => {
// Compiling the TypeScript files to JavaScript and saving them on disk
});
gulp.task('test', ['compile'], () => {
// Running tests with the compiled files
});
gulp.task('minify', ['compile'], () => {
// Minifying the compiled files using Uglify
});
guls.task('default', ['test', 'minify']);
And when I run gulp default
the compile
task is run only 1 time.
In Gulp 4 I implement them this way:
gulp.task('compile', () => {
// Compiling the TypeScript files to JavaScript and saving them on disk
});
gulp.task('test', gulp.series('compile', () => {
// Running tests with the compiled files
}));
gulp.task('minify', gulp.series('compile', () => {
// Minifying the compiled files using Uglify
}));
guls.task('default', gulp.parallel('test', 'minify'));
And when I run gulp default
the compile
task is run 2 times which is undesirable because a spare job is done. How to make the task run only 1 time keeping the ability to run the test
and minify
tasks independently?
Since you are trying to run test and minify in parallel, it's not possible to make run compile only once, since it will become a sequential operation. You could do,
This approach will allow you to run individual operations, and make the test and minify operation parallel while executing the compilation only once.
You can read more details here.