【问题标题】:Exclude sub-directory in gulp.watch排除 gulp.watch 中的子目录
【发布时间】:2014-07-18 22:03:00
【问题描述】:

我想查看所有深度嵌套在模板中的文件,但在构建后排除任何文件夹。

所以排除目录,如:

  • ./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']);

但我真的希望能够在每次添加特定的子子文件夹或子子文件类型时停止更新表达式。怎么能包括除此之外的一切?

【问题讨论】:

    标签: javascript node.js gulp


    【解决方案1】:

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

    想想这样的事情,根据你的需要进行调整:

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

    您也可以查看Gulp Ignore

    【讨论】:

    • 我无法正常工作。我确实找到了npmjs.org/package/gulp-grep-stream
    • @SachinGorade 错误,您不需要插件来否定 glob 模式。
    • @Aperçu 在没有安装 gulp ignore 的情况下尝试它没有工作。
    • 对于以后的读者,否定的glob模式应该放在最后一个索引上,顺序可能会影响结果
    【解决方案2】:

    我知道这是旧的,但您应该排除文件夹文件夹内的所有内容,仅排除文件夹不起作用。

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

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 2010-12-12
      • 2014-12-20
      • 1970-01-01
      • 2014-09-29
      相关资源
      最近更新 更多