Skip to content

Latest commit

 

History

History
82 lines (56 loc) · 2.2 KB

README.md

File metadata and controls

82 lines (56 loc) · 2.2 KB

gulp-rev-rewrite

Build Status npm semantic-release

Effortlessly rewrite references to revisioned assets by incorporating gulp-rev-rewrite into your revisioning workflow powered by gulp-rev.

Install

npm install gulp-rev-rewrite --save-dev

Usage

Option 1: Inline revisioning

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;

Option 2: Separate revisioning and rewriting

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);

API

revRewrite([options])

options

Type: Object

manifest

Type: Buffer (e.g., fs.readFileSync())

Read JSON manifests generated by gulp-rev. This allows replacing filenames that were revisioned in a previous task.

License

MIT © Thomas Vantuycom