gulp-yrevision
v0.0.3
Published
Revises the version of the resource referenced in the html
Downloads
7
Maintainers
Readme
Revises the version of the resource referenced in the html.
- Works with: gulp-hash-list
- Author: JsonZhou
- Author Blog: http://www.2fz1.com/
Install
npm install --save-dev gulp-asset-revision
Usage
var gulp = require('gulp');
var hash = require('gulp-hash-list');
var revision = require('gulp-asset-revision');
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'));
});
gulp.task('revision', ['hash'], function() {
return gulp.src(['./pages/*.html'])
.pipe(revision({
hasSuffix: false,
manifest: './manifest/assets.json'
}))
.pipe(gulp.dest('./pages/'));
});
API
revision(options)
|option|default|description|
|---|---|---|
|manifest||Required, asset manifest file path|
|hasSuffix|false|If true,path matching will add pathSuffix
|
|pathSuffix|-[0-9a-f]{8,10}|Support regular|
hasSuffix和pathSuffix的说明
html中的js或css引用地址是通过{name}{ext}
开头的正则进行匹配的,资源地址可以带参数,如:{name}{ext}?param=value
。
当路径不是{name}{ext}
开头时,gulp-asset-revision
在扫描文件引用地址时,无法正确匹配地址,比如:{name}-{hash}{ext}
。这时需要借助pathSuffix
,帮助gulp-asset-revision
更新好的匹配资源地址,pathSuffix
的作用是匹配{name}
和{ext}
之间的这段,默认值是-[0-9a-f]{8,10}
,需要设置hasSuffix
为true
时才能生效。pathSuffix
支持字符串和正则表达式。