69

I'm a new user to gulp.js. I'd like to move all of my non-javascript files to a build directory. What I've got right now is this:

//Test copy
gulp.task('test-copy', function() {
    gulp.src(['myProject/src/**/*.!(js|map|src)'])
        .pipe(gulp.dest('myProject/build'));
});


//Results for various files
myProject/css/style.css //Copied - GOOD
myProject/html/index.html //Copied - GOOD
myProject/js/foo.js //Not Copied - GOOD
myProject/js/bar.min.js //Copied - BAD!
myProject/js/jquery-2.0.3.min.js //Copied - BAD!
myProject/js/jquery-2.0.3.min.map //Copied - BAD!

As you can see, it only matches after the first dot in the file path string, not the last one, as I'd like. How can I modify the glob search string to behave as I'd like?

AlexZ
  • 11,515
  • 3
  • 28
  • 42
  • I haven't used gulp, but can you just add a $ to the end of the pattern being passed to gulp.src? – James Manning May 09 '14 at 05:49
  • 2
    No, sadly this is not Regex, but rather [extglob](http://www.gnu.org/software/bash/manual/bashref.html#Pattern-Matching) syntax. – AlexZ May 09 '14 at 06:02

1 Answers1

151

Try this glob pattern:

myProject/src/**/!(*.js|*.map|*.src)
TurboHz
  • 2,146
  • 2
  • 16
  • 14
  • 30
    Worked like a charm. For future stragglers, this caused a problem where my `.json` manifest file was also being excluded. I modified the script like so, meaning it still copies `config.js` or `*.json` files: `myProject/src/**/*(config.js|*.json|!(*.js|*.src|*map))` – AlexZ May 09 '14 at 07:16
  • This was extremely helpful for file matching with node's [grunt-ssh](https://github.com/israelroldan/grunt-ssh) and [minimatch](https://github.com/isaacs/minimatch). – craig Jan 05 '17 at 16:53
  • 2
    This is annoying hard to come across even though it seems like such a common thing. – Bill Criswell May 30 '19 at 16:56