How to tell Gulp to skip or ignore some files in gulp.src([...])?
Asked Answered
P

2

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/'));
});
Pashm answered 3/11, 2014 at 5:8 Comment(0)
D
64

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/'));
});
Doorway answered 3/11, 2014 at 5:11 Comment(3)
I do believe that the order matters, and the exclusion must be placed after the inclusion (so it have what to exclude).Frowst
@GustavoVargas Not according to this comment on GitHub. Haven't done much research into it myself though.Doorway
FWIW I tried both orderings and got the same, correct, effect.Ligroin
T
9

Try this:

gulp.src(['css/**/!(ignore.css)*.css'])
Tilghman answered 3/11, 2014 at 5:10 Comment(4)
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 @TilghmanPaediatrician
Thank you. This seems to be working for me var tsFiles = '!(node_modules)/**/*.ts';Endplay
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!Demirelief
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)*.jsOvercast

© 2022 - 2024 — McMap. All rights reserved.