I can't get gulp-if to work correctly.
Without gulp-if it works fine:
gulp.task('css', function() {
return gulp.src([
// 'bower_components/bootstrap/dist/css/bootstrap.css',
'app/stylesheets/main.less',
])
.pipe(less({
strictMath: true,
strictUnits: true,
}))
.pipe(concat('all.css', {newLine: '\n'}))
.pipe(prefixer('> 1%'))
.pipe(minifyCss())
.pipe(gulp.dest('public/css'));
});
But as soon as I add gulp-if
into the mix, the gulpif
pipe returns nothing when it returns to the main stream:
gulp.task('css', function() {
return gulp.src([
'bower_components/bootstrap/dist/css/bootstrap.css',
'app/stylesheets/main.less',
])
.pipe(gulpif(/\.less$/,less({
strictMath: true,
strictUnits: true,
})))
.pipe(concat('all.css', {newLine: '\n'}))
.pipe(prefixer('> 1%'))
.pipe(minifyCss())
.pipe(gulp.dest('public/css'));
});
Why is that? What am I doing wrong? If I add some logs into the gulp-if
source code I can see that the condition is passing.
I think you may want to use gulp-filter
instead: https://www.npmjs.org/package/gulp-filter
gulp.task('css', function() {
var lessFilter = gulpFilter('**/*.less', {restore: true})
return gulp.src([
'bower_components/bootstrap/dist/css/bootstrap.css',
'app/stylesheets/main.less',
])
.pipe(lessFilter)
.pipe(less({
strictMath: true,
strictUnits: true,
}))
.pipe(lessFilter.restore)
.pipe(concat('all.css', {newLine: '\n'}))
.pipe(prefixer('> 1%'))
.pipe(minifyCss())
.pipe(gulp.dest('public/css'));
});
This will create a filtered stream and the restore()
will restore the stream. gulpIf
is made to conditionally process a whole stream and not just matching files.
gulp.src('src/**/*.js', function () {
.pipe(gulpIf(isProduction, concat('all.js')))
.pipe(gulp.dest('dest/')
});
This sounds like a bug in gulp-if
. Try upgrading gulp-if
to the latest version, and if that doesn't work, post an issue on https://github.com/robrich/gulp-if/issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With