栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Gulps gulp.watch是否未触发新文件或已删除文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Gulps gulp.watch是否未触发新文件或已删除文件?

编辑: 显然

gulp.watch
现在可以处理新文件或删除的文件。询问问题时没有。

我剩下的答案仍然

gulp-watch
是:通常是一个更好的解决方案,因为它使您仅可以对已修改的文件执行特定的操作,而
gulp.watch
仅允许您运行完整的任务。对于合理大小的项目,这将很快变得太慢而无法使用。


您什么都不会错过。

gulp.watch
不适用于新文件或删除的文件。这是专为简单项目设计的简单解决方案。

要查看可以查找新文件的文件,请使用功能更强大的

gulp-watch
plugin。用法如下所示:

var watch = require('gulp-watch');// in a taskwatch({glob: <<glob or array of globs>> })        .pipe( << add per-file tasks here>> );// if you'd rather rerun the whole task, you can do this:watch({glob: <<glob or array of globs>>}, function() {    gulp.start( <<task name>> );});

就个人而言,我建议第一种选择。这样可以加快每个文件的处理速度。只要您不连接任何文件,它在使用livereload进行开发的过程中就可以很好地工作。

您可以使用我的

lazypipe
库,也可以仅使用函数来包装流,
stream-combiner
如下所示:

var combine = require('stream-combiner');function scriptsPipeline() {    return combine(coffeeescript(), uglify(), gulp.dest('/path/to/dest'));}watch({glob: 'src/scripts*.js' })        .pipe(scriptsPipeline());

更新 2014年10月15日

如下面的@pkyeck所指出的,显然1.0版对

gulp-watch
格式进行了稍微的更改,因此上述示例现在应为:

var watch = require('gulp-watch');// in a taskwatch(<<glob or array of globs>>)        .pipe( << add per-file tasks here>> );// if you'd rather rerun the whole task, you can do this:watch(<<glob or array of globs>>, function() {    gulp.start( <<task name>> );});

var combine = require('stream-combiner');function scriptsPipeline() {    return combine(coffeeescript(), uglify(), gulp.dest('/path/to/dest'));}watch('src/scripts*.js')        .pipe(scriptsPipeline());


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/392078.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号