36

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/'));
});
Run
  • 54,938
  • 169
  • 450
  • 748

2 Answers2

63

Add a !:

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/'));
});
jdlm
  • 6,327
  • 5
  • 29
  • 49
  • 1
    I do believe that the order matters, and the exclusion must be placed after the inclusion (so it have what to exclude). – Gustavo Vargas Jul 28 '15 at 19:44
  • @GustavoVargas Not according to [this comment](https://github.com/gulpjs/gulp/issues/837#issuecomment-68069722) on GitHub. Haven't done much research into it myself though. – jdlm Jul 29 '15 at 08:01
  • 1
    FWIW I tried both orderings and got the same, correct, effect. – peteorpeter Aug 10 '17 at 21:44
9

Try this:

gulp.src(['css/**/!(ignore.css)*.css'])
qwertymk
  • 34,200
  • 28
  • 121
  • 184
  • 1
    I'm trying to do this with a file ending and it seems to not be working, no idea why! I have `'/**/!(.spec.js)*.js'` Any idea what's wrong with it? Trying everything @qwertymk – Mark Pieszak - Trilon.io Feb 25 '16 at 16:37
  • Thank you. This seems to be working for me `var tsFiles = '!(node_modules)/**/*.ts';` – JonathanPeel Nov 25 '16 at 05:17
  • 1
    This is a very simple way to exclude files/file types. Bravo! My use case was to prevent `.html` files from being copied over in a lib scripts folder, and changing my gulp config src definition for 'lib' to: `lib: './src/assets/scripts/lib/**/!(*.html)*'` did the trick! – tklives Sep 25 '17 at 19:11
  • I had to remove the extension. This worked for me to ignore the app.js file but include alle other js files: assets/js/custom/!(app)*.js – Floris Sep 23 '19 at 11:07