# gulp-asset-revision

> Revises the version of the resource referenced in the html

Latest version **1.0.4** (published 2016-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-asset-revision
pnpm add gulp-asset-revision
yarn add gulp-asset-revision
bun add gulp-asset-revision
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2016-12-09 |
| First published | 2016-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | jsonzhou |
| Maintainers | zzyss86 |
| Keywords | gulpplugin, cache bust, cachebust, revision, asset, static, rev |

## Links

- npm: https://www.npmjs.com/package/gulp-asset-revision
- Repository: https://github.com/zzyss86/gulp-asset-revision
- Homepage: https://github.com/zzyss86/gulp-asset-revision#readme
- Issues: https://github.com/zzyss86/gulp-asset-revision/issues
- npm.io page: https://npm.io/package/gulp-asset-revision

## Dependencies (3)

- [through2](https://npm.io/package/through2.md) ^2.0.3
- [gulp-util](https://npm.io/package/gulp-util.md) ^3.0.7
- [lodash.assign](https://npm.io/package/lodash.assign.md) ^4.2.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2016-12-09
- 1.0.3 — 2016-12-09
- 1.0.2 — 2016-12-09
- 1.0.1 — 2016-12-09
- 1.0.0 — 2016-12-08

## README

Revises the version of the resource referenced in the html.

- Works with: [gulp-hash-list](https://github.com/zzyss86/gulp-hash-list)
- Author: JsonZhou
- Author Blog: [http://www.2fz1.com/](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`支持字符串和正则表达式。

---
_Source: https://npm.io/package/gulp-asset-revision · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
