I'm trying to learn how to put a GulpJS file together and seeing the following source reference in some places */.js but unsure as to what exactly it means. Could someone explain what this is?
If my file structure is something like below, how would I access * each js file in each of the js libs and each js file in js src? * how can i access each image?
css/
libs/
lib1.scss
lib2.scss
src/
partials/
partial1.scss
partial2.scss
partial3.scss
js/
libs/
lib1/
lib11.js
lib2/
lib21.js
lib3/
lib31.js
src/
src1.js
src2.js
src3.js
img/
imgs1/
img11.jpg
img12.jpg
img13.png
imgs2/
img21.gif
img22.png
img23.jpg
It's helpful to have a basic understanding of pattern matching and the module that gulp is using to resolve those glob matches, ie https://github.com/isaacs/minimatch
The **
symbol you're asking about is known as the "globstar". In most unix pattern matching, the *
can only represent one directory level:
"a/*/*.js"
a/b/app.js => MATCH
a/b/c/app.js => NO MATCH
a/app.js => NO MATCH
The globstar allows you to specifiy an unknown number of in-between directories, like so:
"a/**/*.js"
a/b/app.js => MATCH
a/b/c/app.js => MATCH
a/app.js => MATCH
a/b/c/d/e/f/g/h/i/j/app.js => MATCH
other/app.js => NO MATCH
You can negate them with a prepended !
:
["a/**/*.js", "!a/vendor/**/*.js"]
a/b/c/app.js => MATCH
a/vendor/b/backbone.js => NO MATCH
Useful for excluding vendor files from linting, etc.
You can also combine multiple globs in one array to include multiple patterns as one search.
["js/**/*.js", "img/**/*.png"]
js/a/b/app.js => MATCH
img/cat.png => MATCH
The glob you requested would be something like this:
["js/**/*.js", "img/**/*"]
"**/*.js" means "all .js files in all directories under the current one, recursively".
Traditional "*/*.js" means "all .js files in all directories under the current one".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With