grunt-rev-json

Digest files and output rev for each file in a json.
Getting Started
npm install grunt-rev-json --save
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-rev-json');
The "rev_json" task
Overview
In your project's Gruntfile, add a section named rev_json
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
rev_json: {
options: {
algorithm: 'crc32c'
encoding: 'base64',
urlSafe: true,
length: 8
},
your_target: {
src: ['public/**/*.{js,css}']
dest: 'rev.json'
},
},
});
Example
$ pwd
/Users/xiaoyi/Projects/public
$ tree
.
├── scripts
│ ├── desktop.js
│ ├── error.js
│ └── moment.js
└── styles
├── desktop.css
└── mobile.css
grunt.initConfig({
rev_json: {
options: {
algorithm: 'sha224',
length: -1
},
static: {
src: ['public/**/*.{js,css}'],
dest: 'public/rev.json'
}
}
});
{
"scripts/desktop.js": "eSgRA3v4XUcOM66neA7Y2ZfMOX5w0hNWVfuHpQ",
"scripts/error.js": "ZQIiKlJ0_Nj0F8-hi1mnYccZ61rJ5n426vgVBw",
"scripts/mobile.js": "QxB9zfm1PyhYKFMBiqXh9ox8fmCcNmwXWkTRFg",
"styles/desktop.css": "xjrIkYLwmiL6tTMduEjtziR3cr3bJkxyHZ3wQw",
"styles/mobile.css": "YcJ2rs1SI7kbcjgnVO8K0Bf1moFVLwmbPHrVaw"
}
Output JSON will use src path (relative to output file location) as key, and
digest as value.