gulp-asset-revision

1.0.4 • Public • Published

Revises the version of the resource referenced in the html.

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},需要设置hasSuffixtrue时才能生效。pathSuffix支持字符串和正则表达式。

Package Sidebar

Install

npm i gulp-asset-revision

Weekly Downloads

0

Version

1.0.4

License

MIT

Last publish

Collaborators

  • zzyss86