Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp globbing- how to watch everything below directory

Tags:

gulp

glob

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.

like image 474
Jehan Avatar asked Feb 10 '14 22:02

Jehan


People also ask

How do I watch for changes in Gulp?

Gulp - Watch. The Watch method is used to monitor your source files. When any changes to the source file is made, the watch will run an appropriate task. You can use the ‘default’ task to watch for changes to HTML, CSS, and JavaScript files.

How to ignore all files in a directory using gulp?

To ignore all files in a directory, only add the `/**` glob after the directory name. Two or more globs that (un)intentionally match the same file are considered overlapping. When overlapping globs are used within a single src (), gulp does its best to remove the duplicates, but doesn't attempt to deduplicate across separate src () calls.

How to ignore all files in a directory using globbing?

In the previous example, if the negative glob was `!node_modules/**/*.js`, the globbing library wouldn't optimize the negation and every match would have to be compared against the negative glob, which would be extremely slow. To ignore all files in a directory, only add the `/**` glob after the directory name.

What are overlapping Globs in Gulp?

Two or more globs that (un)intentionally match the same file are considered overlapping. When overlapping globs are used within a single src (), gulp does its best to remove the duplicates, but doesn't attempt to deduplicate across separate src () calls.


2 Answers

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.

like image 130
OverZealous Avatar answered Oct 10 '22 09:10

OverZealous


'./src/less/**' seems to work. Still, if someone has a more definitive list of all globbing commands, I would be happy to accept your answer and add it to the gulp docs. Right now you have to go to the docs for one of gulp's submodules, which then gives you a list of manpages. It would be good to have a direct reference, especially for designers using gulp.

like image 20
Jehan Avatar answered Oct 10 '22 09:10

Jehan