
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
gulp-if-else
Advanced tools
[Gulp plugin] Conditional task with "if" callback and "else" callback (optional): gulp.src(source).pipe( ifElse(condition, ifCallback, elseCallback) )
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 ...
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'))
});
gulp-if-else
is unit tested with Unit.js
Run the tests
cd node_modules/gulp-if-else
npm test
Nicolas Talle |
![]() |
FAQs
[Gulp plugin] Conditional task with "if" callback and "else" callback (optional): gulp.src(source).pipe( ifElse(condition, ifCallback, elseCallback) )
The npm package gulp-if-else receives a total of 642 weekly downloads. As such, gulp-if-else popularity was classified as not popular.
We found that gulp-if-else demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.