jrhicks
jrhicks

Reputation: 14997

Exclude sub-directory in gulp.watch

I would like to watch all files deeply nested within templates but exclude any folder after build.

So exclude directories like:

But include directories and files like:

Currently I am having success itemizing the sub-sub-folder names and sub-sub-filetypes

gulp.watch(['templates/*/*.html','templates/*/*.js',
            'templates/*/*.json','templates/*/css/**/*',
            'templates/*/js/**/*'], ['build_templates']);

But I would really like to be able to stop updating the expression every time I add specific sub-sub-folders or sub-sub-filetypes. How can include everything except?

Upvotes: 16

Views: 12222

Answers (2)

Bamieh
Bamieh

Reputation: 10936

I know this is old, but you should exclude the folder and everything inside the folder aswell, excluding the folder alone doesnt work.

gulp.watch(['templates/**/*','!templates/{foo, bar}/build/**/*'], ['build_templates']);

Upvotes: 7

Preview
Preview

Reputation: 35846

I think that you could try to do exclude the build sub directories with the ! sign.

Think of something like this, adapt it to fits your needs :

gulp.watch([
 'templates/**/*',
 '!templates/*/{build,build/**}'
], ['build_templates'])

You could also have a look to Gulp Ignore.

Upvotes: 23

Related Questions