gulp globbing- how to watch everything below directory

Jehan picture Jehan · Feb 10, 2014 · Viewed 83.3k times · Source

This is a pretty dumb question, but I haven't really been able to find a satisfactory answer: How do I use gulp globbing to select all files in all subdirectories below a certain directory?

I've tried:

'./src/less' './src/less/' './src/less/*'

None of them seem to work.

Answer

OverZealous picture OverZealous · Feb 11, 2014

The pattern for all files under all directories is usually ./src/less/**/*.* or ./src/less/**/*, either should work.

Generally speaking, it's better to match specific files extensions — even if they should all be the same — to prevent grabbing system files or other junk. In that case, you can do ./src/less/**/*.less for just .less files, or something like .src/less/**/*.{less,css} for both .less and .css files.

The Grunt website has a pretty good reference for the majority of minimatch globs. (Both Grunt and gulp use minimatch, since it's the glob library for pretty much everything Node related.)

It would be nice for gulp or minimatch to have their own complete docs, but that's open source for you.