Effortlessly rewrite references to revisioned assets by incorporating gulp-rev-rewrite
into your revisioning workflow powered by gulp-rev
.
npm install gulp-rev-rewrite --save-dev
In this approach, revisioning and rewriting are done in a single gulp task.
import gulp from 'gulp';
import rev from 'gulp-rev';
import revRewrite from 'gulp-rev-rewrite';
function revision() {
return gulp.src('dist/**/*.{css,js}')
.pipe(rev())
.pipe(gulp.src('dist/**/*.html'))
.pipe(revRewrite())
.pipe(gulp.dest('dist'));
}
export default revision;
This approach separates asset revisioning from rewriting references to the revisioned assets.
import { readFileSync } from 'node:fs';
import gulp from 'gulp';
import rev from 'rev';
import revRewrite from 'gulp-rev-rewrite';
// Step 1: Asset revisioning
function revision() {
return gulp.src('dist/assets/**/*.{css,js}')
.pipe(rev())
.pipe(gulp.dest('dist/assets'))
.pipe(rev.manifest())
.pipe(gulp.dest('dist/assets'));
}
// Step 2: Rewriting references
function rewrite() {
const manifest = readFileSync('dist/assets/rev-manifest.json');
return gulp.src('dist/**/*.html')
.pipe(revRewrite({ manifest }))
.pipe(gulp.dest('dist'));
}
export default gulp.series(revision, rewrite);
Type: Object
Type: Buffer
(e.g., fs.readFileSync()
)
Read JSON manifests generated by gulp-rev
. This allows replacing filenames that were revisioned in a previous task.
MIT © Thomas Vantuycom