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

Split css for different devices
Gulpfile not working when module.exports references a Gulp task not a function?
Use gulp to process bowser files
Getting an error when trying to serve the app using browser-sync
Can't Sprite using gulp.spritesmith
How can I make build variables available to all JS files in gulp?
Gulp not installed globally?
gulp-useref deep folders error
use gulp+browserify+reactify, can't emit exit when got a ReactifyError
gulp-browserstack and gulp-cucumber don't seem to play nicely together
Gulp - Babel - EcmaScript-6 - Redux / Unhandled stream error in pipe
Delete all files using gulp except once that match pattern
Gulp task 'inject:vendor' does not inject Bower dependencies
Why do you open a gulp src pipe when you use gulp-watch?
Atom action performed on save
Gulp BrowserSync not working with SCSS

Categories

HOME
http
leaflet
cxf
pelican
windows-server-2008
apache-storm
django-middleware
arguments
sms
hibernate-mapping
doctrine2
revit-api
ng2-charts
sha1
openstack-horizon
game-engine
facebook-marketing-api
template10
versioning
draw2d
aiml
caldav
summernote
single-page-application
datasource
typedef
suitescript
resx
launchd
typeorm
ios9
vtd-xml
slim-lang
wercker
dropdownbox
mootools
tunnel
pyenv
flex3
observer-pattern
server-side-swift
mixed-models
sknode
glide-image-library
ape-phylo
firefox-developer-edition
ocpjp
anonymous-function
spring-data-commons
openxava
perldoc
fluent-nhibernate-mapping
activesupport
printer-control-language
acceleo
sharing
glade
git-push
joystick
avaudiorecorder
aws-kms
python-rq
mod
abstract
exchange-server-2007
log4cxx
pushwoosh
joomla3.3
nmock
firewire
android-networking
parseexception
numerical-recipes
illegalargumentexception
novell
parsefloat
windows-search
azure-worker-roles
amzi-prolog
rails-migrations
fastcgi-mono-server
node-mongodb-native
nvcc
xcode5.1
qmainwindow
reference-manual
biztalk-deployment
motorola-droid
inserthtml
ruby-1.9
scriptmanager
virtual-printer
javah
chars
subdirectories
script-tag
djangoappengine
vista64
jettison

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