【问题标题】:excluding certain directories gulp-inject排除某些目录 gulp-inject
【发布时间】:2015-06-28 21:16:01
【问题描述】:

忽略 bower_components 而包括 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

【问题讨论】:

    标签: javascript node.js gulp gulp-inject


    【解决方案1】:

    像这样排除bower_components

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

    【讨论】:

      【解决方案2】:

      我相信顺序很重要。例如,假设我的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});
      

      【讨论】:

        猜你喜欢
        • 2015-09-26
        • 1970-01-01
        • 2011-08-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-21
        • 2021-09-22
        相关资源
        最近更新 更多