regexnode.jsgulpgulp-if

How to use globs to not do an action on a file? (Gulp)


I'm using gulp with gulp-if, gulp-babel, and gulp-uglify, my intent is to not run babel or uglify on minified JS files since the minified files are all lib/vendor files that don't need to be processed. However, they do need to be moved over into the new folder.

Here's what I've got:

.pipe($.if(!/(.min.js)/g,
  $.babel({
     presets: ['es2015']
  })
 ))
.pipe($.if(!/(.min.js)/g,
   $.uglify()
))

I don't think the rest of the context is too important, so I left it out.

The issue that I'm having currently is that the expression isn't working, I guess I wasn't clear on the syntax of how gulp-if works.

What is the best way to do this?


Solution

  • I was able to figure it out..

    I replaced .pipe($.if(/.min.js/g, with .pipe($.if(match,

    Then created the match function..

    function match(file) {
        if (file.path.match(/.min.js/g)) {
            return false;
        } else {
            return true;
        }
    }
    

    Now it works as expected!

    Please let me know if there is an easier/better way to do this!