2015-09-25 55 views
2

我正在阅读我发现的某人的gulpfile.js,并且遇到了一个我以前从未在文件路径中看到过的有趣角色; !符号。我试图为此做一些搜索,但没有任何结果。什么是“!”是否在文件路径中?

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

是否!有一些特殊的意义,在这里?

+0

[从Gulp任务中排除文件/目录]可能的副本(http://stackoverflow.com/questions/23384239/excluding-files-directories-from-gulp-task) – afsantos

回答

9

我不是Gulp的专家,但quick search显示它告诉大家忽略给定的路径。

预先用感叹号标记的路径告诉Gulp排除该目录。

因此,在您的示例中,paths.minJs应该从Gulp正在执行的任务中排除。


其实它是用来否定一个模式,基于answer到另一个问题。也就是说,它用于选择不符合以下模式的内容。因此,它忽略了模式中的路径。

+0

谢谢。我多次阅读它,但那条线从来没有跳过我。 – Ciel

+0

请注意,如果您的任务必须将js编译为缩小的js,则宁愿使用2个不同的文件夹。例如,一个文件夹/ source/js /其文件在min.js中编译到/ dist/js /(或/ public/js /或任何您想要的内容)中。 – CDF

0

Additionnaly到我的上述评论,我到这里报到:

需要注意的是,如果你的任务已经编译JS成精缩JS,你宁愿用2页型动物的文件夹。例如,一个文件夹/ source/js /其文件在min.js中编译到/ dist/js /(或/ public/js /或任何您想要的内容)中。

这一段代码,我经常用在我的大多数项目来连接和丑化我的.js文件:

// 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/')); 
}); 

希望帮助你。

相关问题