revver

0.0.2 • Public • Published

revver npm Version Build Status Coverage Status

Asset versioning for Gulp by appending a content hash to filenames. Similar to gulp-rev.

  • In-memory manifest that persists across Gulp tasks, with support for writing the manifest to disk if needed.
  • Built-in support for interpolating revved paths into file contents. Specify a custom interpolate regex, or specify a callback if you need to modify the revved path (eg. to add a prefix).

Example

'use strict';
 
var gulp = require('gulp');
var Revver = require('revver');
var revver = new Revver();
 
gulp.task('default', ['js'], function() {
  return gulp.src('index.html')
    .pipe(revver.interpolate())
    .pipe(revver.manifest({ clean: false }))
    .pipe(gulp.dest('build'));
});
 
gulp.task('js', function() {
  return gulp.src('script.js')
    .pipe(revver.rev())
    .pipe(gulp.dest('build'));
});

Run the example, or read the tests.

API

var Revver = require('revver');

var revver = new Revver([opts]);

Initialise the revver. opts takes the following keys:

  • manifest — An object literal that maps the original file paths to the revved file paths. Defaults to {}.
  • interpolateRegex — The regular expression used by the interpolate method. Defaults to /{{\s*([^}]+?)\s*}}/g.
  • interpolateCallback — A callback with the signature (revvedPath) for modifying the interpolated value in the interpolate method. Defaults to the identity function.

revver.rev()

Returns a through stream. Computes a hash of each file’s contents and appends said hash to the file’s basename. For example, an initial file.path of bundle.js might become bundle-d41d8cd98f.js.

revver.manifest([opts])

Returns a through stream. Discards all files piped into the stream, before pushing the manifest JSON file into the stream. opts takes the following keys:

  • filename — The name of the manifest file. Defaults to manifest.json.
  • clean — Set to false to pass all files through the stream rather than dropping them. Defaults to true.

revver.interpolate([opts])

Returns a through stream. Interpolate revved paths into the file.contents of files piped into the stream. Pass in opts.interpolateRegex or opts.interpolateCallback to override what had been set in the constructor.

revver.getHashes([opts])

Returns an object literal that maps the original file paths (without the file extensions) to their hashes. If opts.prefix is specified:

  • Only original file paths starting with the prefix will be included in the returned result.
  • The prefix will be trimmed off the original file paths in the result.

Installation

Install via npm:

$ npm i --save-dev revver

License

MIT

Package Sidebar

Install

npm i revver

Weekly Downloads

0

Version

0.0.2

License

MIT

Last publish

Collaborators

  • yuanqing