Git Product home page Git Product logo

gulp-if-else's Introduction

gulp-if-else

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).

Install

npm install gulp-if-else

Usage

ifElse(condition, ifCallback [, elseCallback])

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

// your code ...

gulp.src(source)
  .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();
}else{

  // condition is falsy

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

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

Examples

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

  gulp.src('./public/css/*.css')
    .pipe(ifElse(process.env.NODE_ENV === 'production',

      // called if "NODE_ENV" is "production"
      minifyCSS,

      // called if "NODE_ENV" is "not" "production" (else)
      function() {
        return minifyCSS({debug: true});
    }))
    .pipe(gulp.dest('./dist/css'))
});

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

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

  gulp.src('./public/js/app.js')
    .pipe(browserify())

    // here, "uglify" (function) is called only if "isDev" is "true"
    .pipe(ifElse(isDev, uglify))
    .pipe(gulp.dest('./dist/js'))
});

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

LICENSE

MIT license

Author

Nicolas Tallefourtane - Nicolab.net
Nicolas Talle
Make a donation via Paypal

gulp-if-else's People

Contributors

nicolab avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.