What does “!” mean in file paths?

坚强是说给别人听的谎言 提交于 2019-12-30 20:33:29

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/32791504/what-does-mean-in-file-paths

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!