2014-07-18 45 views
10

我想要观察深度嵌套在模板中的所有文件,但在构建之后排除任何文件夹。排除gulp.watch中的子目录

所以排除目录,如:

  • ./templates/foo/build/**/*

  • ./templates/bar/build/**/*

但是包括目录和文件例如:

  • ./templates/foo/template.html

  • ./templates/foo/css/**/*

  • ./templates/bar/template.html

  • ./templates/bar/css/**/*

目前我有成功的分项列记子子文件夹名称和细分子文件类型

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

但我真的希望能够停止更新表达式,每次我添加特定的子子文件夹或子子文件类型。如何包括除了?

回答

11

我认为你可以尝试使用!符号排除build子目录。

,想出这样的事情,适应它适合您的需要:

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

你也可以看看到Gulp Ignore

+0

我不能得到这个工作。我确实找到了https://www.npmjs.org/package/gulp-grep-stream – jrhicks

+1

这只适用于你安装了gulp-ignore的情况。 –

+1

@SachinGorade错误,你不需要插件来否定glob模式。 –

2

我知道这是旧的,但你应该排除文件夹文件夹内的所有内容,除了文件夹本身不工作。

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