Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including gulp-if-else with all npm packages installed. Try it out:

var gulpIfElse = require("gulp-if-else")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

gulp-if-else v1.0.3

[Gulp plugin] Conditional task with "if" callback and "else" callback (optional): gulp.src(source).pipe( ifElse(condition, ifCallback, elseCallback) )


Actual version published on NPM Dependencies npm module downloads per month

A plugin for Gulp, allows conditional task, with "if" callback and "else" callback (optional).


npm install gulp-if-else


ifElse(condition, ifCallback [, elseCallback])

var ifElse = require('gulp-if-else');

// your code ...

  .pipe( ifElse(condition, ifCallback, elseCallback) )

Works as a basic condition.

To understand the logic, ifElse is equivalent to

if(condition) {

  // condition is truthy

  return ifCallback();

  // condition is falsy

  // if "elseCallback" is provided
  if(elseCallback) {
    return elseCallback();

  // if not "elseCallback" returns the stream
  return stream;


gulp.task('css', function() {

    .pipe(ifElse(process.env.NODE_ENV === 'production',

      // called if "NODE_ENV" is "production"

      // called if "NODE_ENV" is "not" "production" (else)
      function() {
        return minifyCSS({debug: true});

gulp.task('js', function() {

  var isDev = process.env.NODE_ENV === 'development';


    // here, "uglify" (function) is called only if "isDev" is "true"
    .pipe(ifElse(isDev, uglify))

Unit tests

gulp-if-else is unit tested with Unit.js

Run the tests

cd node_modules/gulp-if-else

npm test

Other conditional plugins for Gulp


MIT license


Nicolas Tallefourtane -
Nicolas Talle
Make a donation via Paypal
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free