Glob matching, exclude all JS files
Asked Answered
H

1

68

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?

Hannie answered 9/5, 2014 at 5:36 Comment(2)
I haven't used gulp, but can you just add a $ to the end of the pattern being passed to gulp.src?Symptomatic
No, sadly this is not Regex, but rather extglob syntax.Hannie
H
151

Try this glob pattern:

myProject/src/**/!(*.js|*.map|*.src)
Heaviside answered 9/5, 2014 at 6:49 Comment(4)
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))Hannie
This was extremely helpful for file matching with node's grunt-ssh and minimatch.Tlemcen
This is annoying hard to come across even though it seems like such a common thing.Hungnam
What if I want to match a file name with a specific prefix, say foo? Would it be foo*!(*.js)?Preiser

© 2022 - 2024 — McMap. All rights reserved.