How can I use a glob to ignore files that start with an underscore?

前端 未结 4 1904
暖寄归人
暖寄归人 2020-12-16 12:35

I am using this file matching in gulp:

\'content/css/*.css\'

But I would like to only include the files that do not start

相关标签:
4条回答
  • 2020-12-16 13:08

    If Gulp wildcards are like shell wildcards:

    content/css/[^_]*.css
    

    The ^ at the beginning of a character set means to match any characters not in the set.

    0 讨论(0)
  • 2020-12-16 13:13

    You could use this regex.

    content/css/[^_].*\.css
    

    Add $ at the last if necessary.

    0 讨论(0)
  • 2020-12-16 13:17

    You can add a second glob whitch will filter files or folders with an underscore.

    For ignore folders I use:

    gulp.src(['./src/**/*.html', '!**/_*/**'])
    

    '!**/_*/**' will filter folders that start with an underscore.

    0 讨论(0)
  • 2020-12-16 13:22

    Use this plugin https://github.com/robrich/gulp-ignore

    var gulpIgnore = require('gulp-ignore');
    var condition = '_*.css'; //exclude condition
    
    gulp.task('less', function() {
      gulp.src('content/less/*.less')
        .pipe(gulpIgnore.exclude(condition))
        .pipe(less())
        .pipe(gulp.dest('/dist/'));
    });
    

    I think gulp supports file glob not full-regex, But You can give a try to content/css/[^_]*.less

    0 讨论(0)
提交回复
热议问题