6

I am reading over someone's gulpfile.js that I found, and came across an interesting character that I've not seen in file paths before; the ! symbol. I tried to do some searches for this but yielded nothing.

gulp.task("min:js", function () {
    gulp.src([paths.js, "!" + paths.minJs], { base: "." })
        .pipe(concat(paths.concatJsDest))
        .pipe(uglify())
        .pipe(gulp.dest("."));
});

Does the ! have some particular meaning, here?

JJJ
  • 32,902
  • 20
  • 89
  • 102
Ciel
  • 4,290
  • 8
  • 51
  • 110
  • 1
    possible duplicate of [Excluding files/directories from Gulp task](http://stackoverflow.com/questions/23384239/excluding-files-directories-from-gulp-task) – afsantos Sep 25 '15 at 22:33

2 Answers2

14

I'm not an expert on Gulp, but a quick search shows that it tells gulp to ignore a given path.

Prepending a path with an exclamation mark tells Gulp to exclude that directory.

So, in your example, paths.minJs should be excluded from the task Gulp is performing.


Actually it is used to negate a pattern, based on the answer to another question. That is, it is used to select what does not match the following pattern. As a consequence, it ignores the path in the pattern.

Community
  • 1
  • 1
afsantos
  • 5,178
  • 4
  • 30
  • 54
  • 1
    Thanks. I read over it several times but that line just never jumped at me. – Ciel Sep 25 '15 at 22:43
  • Note that if your task has to compile js into minified js, you would rather use 2 differents folders. As an example, a folder /source/js/ whose files are compiled in min.js into /dist/js/ ( or /public/js/ or anything you want ). – CDF Sep 26 '15 at 08:05
  • you have saved my day. Thanks! – fablexis Nov 20 '19 at 23:08
0

Additionnaly to my above comment that I report here:

Note that if your task has to compile js into minified js, you would rather use 2 differents folders. As an example, a folder /source/js/ whose files are compiled in min.js into /dist/js/ ( or /public/js/ or anything you want ).

This a piece of code I often use to concatenate and uglify my Js files in most of my projects:

// My task called jsmin depend on another task, assume it is called clean but could be whatever
// That means that until the clean task is not completed, the jsmin task will not be executed.
gulp.task( 'jsmin', ['clean'], function() {

    // First I clean the destination folder
    del([ 'public/js/*' ]);

     // Then I compile all the Js contained in source/js/ into min.js into public/js/
     // In my example I concatenate all the Js together then I minimize them.
     return gulp.src( 'source/js/*.js' )
    .pipe(concat( "js.min.js" ))
    .pipe(uglify())
    .pipe(gulp.dest('public/js/'));
});

Hope that helps you.

CDF
  • 194
  • 5