Questions tagged [gulp-if]

gulp-if is a gulp plugin for conditional control of the flow of vinyl objects.

gulp-if is a gulp plugin for conditional control of the flow of vinyl objects. It works like a conditional stream filter in several different modes (simple condition, ternary).

Ternary filter example:

var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var beautify = require('gulp-beautify');

var condition = function (file) {
  // TODO: add business logic 
  return true;
}

gulp.task('task', function() {
  gulp.src('./src/*.js')
    .pipe(gulpif(condition, uglify(), beautify()))
    .pipe(gulp.dest('./dist/'));
});

gulp-if npm package: https://www.npmjs.com/package/gulp-if.

21 questions
5
votes
3 answers

How to use gulp-if to conditionally compile less files?

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({ …
mpen
  • 272,448
  • 266
  • 850
  • 1,236
3
votes
1 answer

How apply ng-annotate and then uglify inside gulp-if?

Here is my minification gulp task: var gulp = require('gulp'), useref = require('gulp-useref'), gulpif = require('gulp-if'), uglify = require('gulp-uglify'), minifyCss = require('gulp-minify-css'), ngmin = require('gulp-ngmin'), ngAnnotate =…
splash27
  • 2,057
  • 6
  • 26
  • 49
3
votes
2 answers

Conditionals in gulp

I'm a bit confused over how to best set up conditionals in a gulp file and could use some clarification. Am I right in that you cannot do ordinary if statements inside a pipe chain? If you can, how would you type it out? Right now I'm using gulp-if…
Johan Dahl
  • 1,672
  • 3
  • 19
  • 35
2
votes
5 answers

Conditional gulp task inside gulp.paralell() or gulp.series()

Too much information about conditions tasks inside pipes (e. g. "gulp-if" plugin). However, actually it is not "conditional tasks": it is the "conditional plugin usage", and one task can use multiple plugins. Here is how to conditionally run task…
Takeshi Tokugawa YD
  • 670
  • 5
  • 40
  • 124
2
votes
2 answers

Skip uglifying already compressed files with Gulp

I have a situation where I was currently uglifying all JavaScript files even if they were already compressed, which obviously isn't a great idea. My respective task was: gulp.task('uglify', ['scripts'], function() { return…
Brett
  • 19,449
  • 54
  • 157
  • 290
2
votes
3 answers

Using gulp-if with gulp-useref and gulp-uglify

I want to use gulp-useref to concatenate all of my JavaScript files into one. Within my JavaScript files I have a mixture of pre-minified and non-minified files. I would like to only uglify files which are not already minified (for build…
atwright147
  • 3,694
  • 4
  • 31
  • 57
1
vote
1 answer

Stylus pre-processor won't work inside useref with gulpif

I have a very basic gulp task, and I want to process a Stylus CSS file (.styl). This is the task inside the gulpfile: const gulp = require("gulp"); const gulpIf = require("gulp-if"); const useref = require("gulp-useref"); const stylus =…
user5979874
1
vote
1 answer

Gulp: Object # has no method 'if'
I have cloned a repo with a working gulpfile.js, and now when running gulf on the cloned repo, I received the error Object # has no method 'if' The offending task code: gulp.task('html', ['styles'], function () { return…
bullcitydave
  • 925
  • 1
  • 8
  • 19
0
votes
0 answers

Why doesn't gulp-if divert to branches as I'd expect?

I'm having basic problems with gulp-if. From the documentation I understand, that if condition is true, execute first part and (optionally) if not, then execute 2nd part. So I wrote this gulpfile.js. But it is absolutly not doing what I would have…
jamacoe
  • 519
  • 4
  • 16
0
votes
1 answer

Is there a way to fix Nunjucks changing file extensions to .html?

I have a gulpfile that processes both HTML and PHP files using a template manager (Nunjucks) which works fine but I think the process could be improved. Currently I am using one task to process the HTML files and another one to process the PHP…
0
votes
1 answer

Verify if certain string exists in html page

I have some js and html files in my folder and I want to verify that no js file or html file contains http:// For the js files I used gulp-contains and it worked perfectly but it's not working for html pages. I want any gulp module that will verify…
Ask
  • 3,076
  • 6
  • 30
  • 63
0
votes
1 answer

Multiple streams inside single gulp-if calling?

In the below code, I do plugins.if( !config.isDevelopmentMode && config.compileBladeTemplates, /* task */) check twice (plugins.if is gulp-if package). Can I refactor below code with one check? Not sure that it possible just with gulp-if, so it's…
Takeshi Tokugawa YD
  • 670
  • 5
  • 40
  • 124
0
votes
1 answer

gulp-If. How to check if js file contains specific property?

I am using gulp.js. But I want to add a condition that if request.debug = true; in any of my js file then gulp task should fail. I have found gulp-if and gulp-fail that I can use for this purpose but I don't know that how can I check the specific…
Ask
  • 3,076
  • 6
  • 30
  • 63
0
votes
2 answers

Gulpfile task to copy files should optimize images if there are any

In my gulpfile I'm copying multiple globs of files (various formats) and if any of these globs contains an image I'd like to optimize it with gulp-imagemin. Problem is gulp-imagemin expects only images otherwise throws unsupported image in the log,…
Xeevis
  • 4,325
  • 25
  • 26
0
votes
1 answer

Switch output folder based on filename in gulp task

I have different *.scss files in my src folder and I want one file to be compiled in its own separate folder. Lets assume I have the files normalFile_1.scss, specialFile.scss, normalFile_2.scss. I want the two normal files to be compiled to the…
0x1234
  • 101
  • 2
  • 11
1
2