gulp.src exclude all files matching a pattern except one - not working?

1k Views Asked by At

This is what I've got.

gulp.src(["app/**/*.js" "!app/environment.*.js","app/environment.prod.js"], {read: false})

I was expecting it to include only environment.prod.js and exclude all other environment.*.js. But it excludes all of them.

Only way I could get it to work is to not use wildcard for exclusion and repeat them like this.

gulp.src(["app/**/*.js",
          "!app/environment.test.js", 
          "!app/environment.uat.js",
          "app/environment.prod.js"], {read: false});

Any ideas?

1

There are 1 best solutions below

1
On

If you only need the app/environment.prod.js, then just pass that to gulp.src

Edit

gulp.src(["app/**/*.js", "!app/environment.+(test|uat|bla).js"], {read: false})

Will exclude: app/environment.test.js, app/environment.uat.js, app/environment.bla.js.

For reference, see this: https://github.com/isaacs/minimatch#usage

I refer to minimatch project because internally gulp uses that for their purposes