Generates file hash to the JSON manifest file and generates new file name.
- Works with: gulp-asset-revision
- Author: JsonZhou
- Author Blog: http://www.2fz1.com/
npm install --save-dev gulp-hash-list
var gulp = require('gulp');
var hash = require('gulp-hash-list');
gulp.task('hash', function() {
return gulp.src(['./src/**/*.js','./src/**/*.css'])
.pipe(hash({
"template": "{name}{ext}?hash={hash}"
}))
.pipe(gulp.dest('./dist'))
.pipe(hash.manifest('assets.json'))
.pipe(gulp.dest('./manifest'));
});
option | default | description |
---|---|---|
algorithm | sha1 | crypto.createHash(algorithm) |
hashLength | 8 | hash string length |
template | {name}{ext}?hash={hash} | file name template |
name | description |
---|---|
{name} | file name |
{ext) | file extension, Required |
{hash} | file contents hash |
{size} | file size |
{atime} | Access Time, return UTC |
{mtime} | Modified Time, return UTC |
{ctime} | Change Time, return UTC |
manifestPath:manifest file name.
Gulp生态已经有比如:gulp-hash
这样优秀的生成文件Hash的库,但是为什么还要造一个gulp-hash-lish
呢? 因为在使用过程中,需要更加灵活的对文件名进行变更,比如文件名加参数后,应该生成以文件后缀结尾的文件,而不是带参数的文件名。
如:
模板:
{name}{mtime}{ext}?hash={hash}
生成以后缀结尾的文件,而不是参数结尾的不合法文件名:
{name}{mtime}{ext}
但HTML引用变成:
{name}{mtime}{ext}?hash={hash}