gulp


How to run some gulp task based on a conditional


Suppose I have this in my gulpfile:
gulp.task('foo', ...);
gulp.task('bar', function () {
if (something) {
// how do I run task 'foo' here?
}
});
You could make 'bar' a dependency of 'foo' and put the condition inside 'foo':
gulp.task('foo', function(){
if(something){...}
}, 'bar');
gulp.task('bar', function(){});
This way bar will always run before foo, and foo can choose if it is necessary to run its own logic.
Gulp v3
Use deprecated but still working gulp.run
gulp.task('foo', ...)
gulp.task('bar', function () {
if (something) {
gulp.run('foo')
}
})
Alternatively, use use any plugins that consume task names as arguments, like run-sequence for example (which you will probably need anyway for running tasks in a strict sequence). I call my tasks conditionally this way (Gulp v3):
gulp.task('bar', (callback) => {
if (something) {
runSequence('foo', callback)
} else {
runSequence('foo', 'anotherTask', callback)
}
})
Gulp v4
Your gulpfile, that is, gulpfile.babel.js for now, would set Gulp tasks as exported functions so you would call them directly:
export function foo () {
...
}
export function bar () {
if (something) {
foo()
}
}

Related Links

How to pass array from gulp to other js files?
BrowserSync + Gulp with Vagrant not refreshing
gulp-tslint return undefined when required
Gulp watch only runs once
Gulp watch not working with imported files but works with main file
Gulp watch for css doesn't work
Using gulp for compiling of changed files only
How to run gulp task in visual studio code?
BrowserSync with custom URL
Multi-tenancy and Semantic UI
Display total number of errors with Gulp Jshint
Gulp watch entire folder & compile saved file
elixir.queueTask is undefined
gulp : browserify then concat files
parse error on vinyl source stream on gulp browserify babelify project
Bitters error (“Undefined variable: $font-stack-system”)

Categories

HOME
ckan
ssms
macros
teradata
cluster-analysis
postgresql-9.3
window.open
c++builder
richtextbox
country-codes
minimax
runtime
angular-universal
opengrok
eclipse-orion
background-image
openscad
hapijs
hl7-fhir
openoffice-basic
custom-component
vala
combinations
dev-c++
connectiq
javaagents
opengraph
fastboot
concatenation
grunt-contrib-uglify
scalatest
folder
drawrect
tikz
loopback
android-geofence
asp.net-webhooks
pymunk
javafxports
rythm
realloc
jquery-inputmask
cowboy
ssdp
angular-fullstack
jcifs
multi-targeting
codesniffer
trusted-computing
boost-range
qtruby
periodic-processing
dday
cascading
opendolphin
gtkwave
tvp
random-sample
windows-phone-8-emulator
gcc-warning
mergecursor
xmla
nsurlrequest
parsefloat
javacompiler
indic
visual-studio-setup-proje
traceur
logo-lang
ekevent
octokit
oc4j
friendly-url
pudb
cloudmade
reference-manual
blotter
ncml
cryptarithmetic-puzzle
nsscrollview
optimistic-concurrency
project-files
datejs
yii-cactiverecord
rjs
flexbuilder
jquery-attributes
system-analysis
linq-to-mysql
code-golf
cons

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App