如何告诉 Gulp 跳过或忽略 gulp.src([...]) 中的某些文件?

2022-01-12 00:00:00 css gulp gulp-concat

如何让 Gulp 跳过或忽略 gulp.src([...]) 中的某些文件?例如,我不想在我的 css/文件夹中压缩和合并这个文件 - 'css/ignnore.css'?

How can I tell Gulp to skip or ignore some files in gulp.src([...])? For instance, I don't want to compress and concat this file in my css/ folder - 'css/ignnore.css'?

var autoprefix = require('gulp-autoprefixer'),
    concat = require('gulp-concat'),
    minifyCss = require('gulp-minify-css');

gulp.task('styles', function() {
  gulp.src([
      'css/ignnore.css', // ignore this file
      'css/*.css'
    ])
    .pipe(concat('styles.css'))
    .pipe(autoprefix('last 2 versions'))
    .pipe(minifyCss())
    .pipe(gulp.dest('local/view/style/base/css/dist/'));
});

推荐答案

添加一个:

gulp.task('styles', function() {
  gulp.src([
      '!css/ignnore.css', // <== !
      'css/*.css'
    ])
    .pipe(concat('styles.css'))
    .pipe(autoprefix('last 2 versions'))
    .pipe(minifyCss())
    .pipe(gulp.dest('local/view/style/base/css/dist/'));
});

相关文章