title: Using uglify and minify with if condition in gulp
body: <p>I want to minify and uglify all the <strong>*.js</strong> files in a folder and push the result to another folder using <strong>Gulp</strong> based on a certain condition, like if I pass the <strong>env</strong> parameter as <strong>prod</strong> then only this should happen as in:</p>
  
  <p>Here is my <strong>gulpfile.js</strong>:</p>
  
  <pre><code>var gulp                    = require('gulp');
  var gminify                 = require('gulp-minify');
  var gif                     = require('gulp-if');
  var guglify                 = require('gulp-uglify');
  var args                    = require('yargs').argv;
  
  
  gulp.task('minify_js', function(){
      return gulp
              .src('app/js/*.js')//TAKE ALL THE JS FILES FROM THE FOLDER  
              .pipe(gif(args.env === "prod", gminify()))//DO MINIFY ONLY IN CASE env === prod
              .pipe(gif(args.env === "prod", guglify()))
              .pipe(gulp.dest('dist/js'));//PASTES THEM TO dist/js folder after processing
  });
  </code></pre>
  
  <p>Now for running this I am using like this:</p>
  
  <pre><code>gulp minify_js --env prod
  </code></pre>
  
  <p>In this case whenever I give <strong>--env</strong> value as <strong>prod</strong> the minified version gets generated which is ok but it is not in <strong>uglify</strong> format. </p>
  
  <p>Also just <strong>for the reference</strong> there is a <strong>js</strong> file inside of <strong>app/js</strong> named <strong>test.js</strong> and its content is as follows:</p>
  
  <pre><code>var abc = function(){
     console.log("This is just a test message");
  };
  abc();
  </code></pre>
  
  <p>After running, 2 files gets generated inside of <strong>dist/js</strong> namely <strong>test.js</strong> (whose content is same) and <strong>tests.min.js</strong> whose content is like this:</p>
  
  <pre><code>var abc=function(){console.log("This is just a test message")};abc();
  </code></pre>
  
  <p>which looks like <strong>minified</strong> but not the <strong>uglified</strong>.</p>
  
  <p>So my question is what I missed?</p>
  
  <p><strong><em>FYI:</strong> I already installed <strong>gulp, gulp-minify, gulp-if, gulp-uglify, yargs</strong> as development dependencies.</em></p>