A Broccoli plugin for adding revision checksums to file names
A Broccoli plugin that adds the checksum of files to the output filename. This is useful in situations where you need unique names for asset files so you can bust HTTP caches.
broccoli-rev is actually two plugins in a single module.
The first plugin (called
rev) maps every file in the input tree to a file with the same name + a hash of the file's contents. For example, a file named
styles/fonts.css in the input tree might be named
styles/fonts-83f26306.css in the output. This step also generates a manifest file in the output that contains a map of all the original file paths to their new versions.
var rev = ;var revvedTree =;
The second plugin in this module is optional, but represents a common use case. Basically, it takes the manifest file from the first step and interpolates its values into a Handlebars template using a
rev helper function.
index.hbs file might look like this:
You might also have a
scripts directory that contains source versions of all the scripts you want to run on your HTML page. In this scenario, you could use the following
Brocfile.js to build rev'd versions of the scripts and interpolate the rev'd file names into the template for
var pickFiles = ;var mergeTrees = ;var rev = ;var indexTree =;// scriptsTree is a rev'd version of all files in the scripts// source directory + the rev-manifest.json file.var scriptsTree =;var indexAndScriptsTree = ;// Render index.hbs => index.html using a rev Handlebars helper// function that looks up paths in the rev-manifest.json file.moduleexports = rev;