gulp-newer vs gulp-changed [英] gulp-newer vs gulp-changed

查看:22
本文介绍了gulp-newer vs gulp-changed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们之间有什么区别?

gulp-newer:

gulp.src(imgSrc)
  .pipe(newer(imgDest))
  .pipe(imagemin())
  .pipe(gulp.dest(imgDest));

gulp-changed:

gulp.src(SRC)
    .pipe(changed(DEST))
    // ngmin will only get the files that
    // changed since the last time it was run
    .pipe(ngmin())
    .pipe(gulp.dest(DEST));

似乎gulp-changed更强大,因为它提供了一个选项

It seems gulp-changed is more powerful, because it provides an option

hasChanged: changed.compareLastModifiedTime

推荐答案

希望现在回答这个问题还为时不晚.对于最近的一个项目,我不得不在源代码级别评估它们,这是我的看法.

I hope it's not too late to answer this question. I have had to evaluated both of them at a source-code level for a recent project, and here is my take.

这个插件的核心是比较源文件和目标文件的修改时间(参见node API)来决定源文件是否比目标文件新,或者根本没有目标文件.下面是插件中的相关代码:

At the core, this plugin compares the source and dest file's modified time (see node API) to decide whether the source file is newer than the dest file or if there is no dest file at all. Here is the related code in the plugin:

var newer = !destFileStats || srcFile.stat.mtime > destFileStats.mtime;

gulp 改变

这个插件默认也使用文件的修改时间来决定要通过哪个流

gulp-changed

This plugin by default also uses a file's modified time to decide which to pass through the stream

function compareLastModifiedTime(stream, cb, sourceFile, targetPath) {}

但它更进了一步,提供了一个比较文件内容 SHA1 哈希的选项:

but it goes one step further by offering an option to compare the file's content SHA1 hash:

function compareSha1Digest(stream, cb, sourceFile, targetPath) {}

此信息很好地记录在案.

所以理论上来说,如果你使用 gulp-changed 的​​默认 hasChanged: changed.compareLastModifiedTime,那么每个插件相对来说都一样快.如果您使用 gulp-changed 的​​ hasChanged: changed.compareSha1Digest,则可以合理预期 gulp-changed 会慢一些,因为它确实会创建文件内容的 SHA1 哈希.我没有进行基准测试,但我也有兴趣看到一些数字.

So theoretically speaking, if you use gulp-changed's default hasChanged: changed.compareLastModifiedTime, each plugin is relatively as fast as the other. If you use gulp-changed's hasChanged: changed.compareSha1Digest, it's reasonable to expect gulp-changed to be a bit slower because it does create a SHA1 hash of the file content. I didn't benchmark but I'm also interested in seeing some number.

gulp-changed,纯粹是因为它背后的开发者(sindresorhus).如果有一天这个了不起的人决定停止支持他的 gulp 插件,我想我会完全停止使用 gulp.

gulp-changed, purely because of the developer behind it (sindresorhus). If one day this awesome man decides that he will stop supporting his gulp plugins, I think I will stop using gulp altogether.

不过,开个玩笑,gulp-changed 的​​源代码是 gulp-y,而 gulp-newer 的源代码读起来很像另一个节点模块的源代码,其中包含许多承诺.所以 gulp-changed 的​​另一个 +1 :)

Joking aside, though, gulp-changed's source code is gulp-y, while gulp-newer's source reads pretty much like just another node module's source with lots of promises. So another +1 for gulp-changed :)

Gulp-changed 仅适用于 1:1 source:dest 映射.如果您需要很多:1,例如与 gulp concat 一起使用时,请选择 gulp-newer.

Gulp-changed only works with 1:1 source:dest mapping. If you need many:1, e.g. when using with gulp concat, choose gulp-newer instead.

这篇关于gulp-newer vs gulp-changed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆