吞噬新一代vs吞噬改变 [英] gulp-newer vs gulp-changed

查看:143
本文介绍了吞噬新一代vs吞噬改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们之间的区别是什么?



gulp-newer

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

gulp-change

  gulp.src(SRC)
.pipe(已更改(DEST))
// ngmin只会得到自
//上次运行以来更改的文件
.pipe(ngmin())
.pipe(gulp .dest(DEST));

看起来gulp-changed的功能更强大,因为它提供了一个选项

  hasChanged:changed.compareLastModifiedTime 


解决方案

我希望现在回答这个问题还为时不晚。我必须在最近的一个项目的源代码级别上对它们进行评估,这里是我的看法。



gulp-newer



这个插件的核心是比较源文件和目标文件的修改时间(请参阅节点API < a>)来决定源文件是否比dest文件更新或根本没有dest文件。这里是插件中的相关代码:

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



gulp-changed



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



$ p $函数compareLastModifiedTime(stream,cb,sourceFile,targetPath) {}

但通过提供一个选项来比较文件的内容SHA1 hash:

 函数compareSha1Digest(stream,cb,sourceFile,targetPath){} 

这些信息很好地记录。结论

理论上讲,如果你使用gulp-changed的默认值 hasChanged: changed.compareLastModifiedTime ,每个插件的速度都相当快。如果使用gulp-changed的 hasChanged:changed.compareSha1Digest ,那么期望gulp-changed有点慢是合理的,因为它会创建文件内容的SHA1散列。我没有进行基准测试,但我也有兴趣看到一些数字。



选择哪个



gulp纯粹是因为它背后的开发者(sindresorhus)。如果有一天这个真棒男人决定停止支持他的大嘴插件,我想我会停止使用吞咽。



然而,开玩笑说,gulp-changed的源代码是gulp-y,而gulp-newer的源代码读起来就像是另一个有很多承诺的节点模块的源代码。所以,另一个改变为gulp的方法是:)

巨大的编辑



Gulp-changed仅适用于1: 1个来源:dest映射。如果你需要很多:1,例如当使用gulp concat时,请选择gulp-newer。


What're the differences between them?

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));

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.

gulp-newer

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-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) {}

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

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

This information is nicely documented.

Conclusion

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.

Which to choose

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.

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 :)

HUGE EDIT

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.

这篇关于吞噬新一代vs吞噬改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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