Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kwoktung/gulp-tpl-rev
template asset url revisioning by appending content hash to filenames: `unicorn.css` → `unicorn.css?_v=1`
https://github.com/kwoktung/gulp-tpl-rev
gulp gulp-plugin revisioning template
Last synced: 19 days ago
JSON representation
template asset url revisioning by appending content hash to filenames: `unicorn.css` → `unicorn.css?_v=1`
- Host: GitHub
- URL: https://github.com/kwoktung/gulp-tpl-rev
- Owner: kwoktung
- Created: 2019-09-28T09:34:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-28T03:42:05.000Z (over 5 years ago)
- Last Synced: 2024-11-07T01:49:56.404Z (3 months ago)
- Topics: gulp, gulp-plugin, revisioning, template
- Language: TypeScript
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gulp-tpl-rev [![Build Status](https://api.travis-ci.org/kwoktung/gulp-tpl-rev.svg?branch=master)](https://travis-ci.org/kwoktung/gulp-tpl-rev)
> Static asset revisioning by appending content hash to filenames
> ``unicorn.css` → `unicorn.css?_v=995025`## Install
```
$ npm install --save-dev gulp-tpl-rev
```## Usage
```js
const gulp = require('gulp');
const tpl = require('gulp-tpl-rev');
const crypto = require('crypto');
const path = require('path');
const fs= require('fs')exports.default = () => (
gulp.src('src/*.html')
.pipe(tpl( function(pathname) {
const { ext } = path.parse(pathname)
const fullpath = path.join(__dirname, 'wwwroot', pathname)
if (fs.existsSync(fullpath)) {
const file = fs.readFileSync(fullpath, 'utf8')
const md5 = crypto.createHash('md5');
md5.update(file);
return md5.digest('hex').slice(0, 6)
}
return ""
}
))
.pipe(gulp.dest('dist'))
);
```