排除特定目录 gulp-inject

3
忽略文件夹,同时包含cssjavascript文件。
gulp.task('files', function(){
    var target = gulp.src("./client/index.html");
    var sources = gulp.src(["./client/**/*.js", "./client/**/*.css"], {read: false});

    target.pipe(inject(sources))
        .pipe(gulp.dest("./client"))    
});

我不想在我的index.html中包含client/bower_components文件夹,有没有一种方法可以指定我的sources中要包含哪些文件?

https://github.com/klei/gulp-inject#optionsignorepath

2个回答

3
像这样排除 bower_components
var sources = gulp.src(["!./client/bower_components/**/*"                 "./client/**/*.js", "./client/**/*.css"], {read: false});

0

我相信顺序很重要。例如,假设我在我的client文件夹中有一个tests文件夹,其中包含所有客户端代码。我不想在生成的index.html中包含我的规范。

最初我有

var sources = gulp.src([
    '!./client/tests/**/*', // exclude the specs up front, didn't work
    './client/config/app.js',
    './client/config/*.js',
    './client/**/*.js', // conflicts with the tests exclusion   
    './client/**/*.css'
], {read: false});

但它仍然将规范注入到我的HTML中!问题在于我告诉gulp在排除一个client文件夹之后包含所有client文件夹。所以我只需要把被排除的文件夹放在最后就可以解决这个问题。

var sources = gulp.src([
    './client/config/app.js',
    './client/config/*.js',
    './client/**/*.js',
    './client/**/*.css',
    '!./client/tests/**/*' // exclude the specs at the end, works!
], {read: false});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接