JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5161
  • Score
    100M100P100Q118130F

A gulp plugin for cachebusting files by adding a hash to their name and/or content. Optionally writes a JSON file with mappings from the original filename to the renamed one.

Package Exports

  • gulp-hash

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-hash) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gulp-hash NPM version Build Status

Gulp plugin for cachebusting files by adding a hash to their name and/or content. Optionally writes a JSON file with mappings from the original filename to the renamed one.

Basic usage

var hash = require('gulp-hash');

// ...

gulp.src('./js/**/*')
    .pipe(hash()) // Add hashes to the files' names
    .pipe(gulp.dest('public/js')) // Write the now-renamed files
    .pipe(hash.manifest('asset-hashes.json')) // Change the stream to the manifest file
    .pipe(gulp.dest('public')); // Write the manifest file

API

hash(options)

Option Default Description
algorithm 'sha1' A hashing algorithm for crypto.createHash or equivalent custom function
hashLength 8 The length of the hash to add to the file's name (substr from the start of the full hash)
template '<%= name %>-<%= hash %><%= ext %>' Format for renaming the files
version '' A key to change the files' hashes without actually changing their content; appended to the contents when hashing

hash.manifest(manifestPath, append)

Option Default Description
manifestPath The desired path to the manifest file
append false Whether to merge the new manifest with an existing one's contents (same filename, doesn't have to exist before first run)

A more advanced example

See example/example-gulpfile.js for an example for a full gulpfile.
Note: The example is out of date, but should work; it is, however, way more convoluted than it has to be and will be updated later.