I have two requirements for my build script:
gulp clean build
, clean
must complete before build
starts. gulp build
, then clean
shouldn't run.So, if clean
is specified, then build
should wait for it, else start.
The first part is possible if I do
gulp.task('clean');
gulp.task('build', ['clean']);
However, that violates point 2
If I do
gulp.task('clean');
gulp.task('build');
That violates point 1
Is this possible with gulp?
You cannot run two gulp tasks with the same command like you did with dependency management you want.
Anyway you can pass an argument to your build
task that will allow, using a little ternary, to wait for the clean
one to complete before running.
So something like this:
gulp.task('build', (process.argv[3] === '--clean') ? ['clean'] : null, function () {
...
});
This way, you can launch your build normally with
gulp build
And when you want to call it with the clean
:
gulp build --clean
There is a lot of ways to get better argument handling, like yargs or the env of gulp-util. But I found my method nice in the fact that it doesn't need any extra dependency.
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