A grunt task which hashes all scripts and stylesheets with integrity attributes.
npm install grunt-sri-hash> A grunt task which hashes all scripts and stylesheets with integrity attributes.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
``shell`
npm install grunt-sri-hash --save-dev
One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
`js`
grunt.loadNpmTasks('grunt-sri-hash');
In your project's Gruntfile, add a section named sri_hash to the data object passed into grunt.initConfig().
`js`
grunt.initConfig({
sri_hash: {
options: {
algorithm: "sha512",
selector: 'script[src]:not([integrity]):not([src^="http"]):not([src^="//"])'
},
all: {
files: {
'dest-index.html': 'source-index.html',
},
},
},
});
#### algorithm
Defaults to sha384.
`js
grunt.initConfig({
sri_hash: {
all: {
options: {
algorithm: 'sha384'
},
files: {
'dest-index.html': 'source-index.html',
},
},
},
});
`
#### selector
Defaults to link[rel=stylesheet][href]:not([integrity]):not([href^="http"]):not([href^="//"]), script[src]:not([integrity]):not([src^="http"]):not([src^="//"]).
`js
grunt.initConfig({
sri_hash: {
all: {
options: {
selector: 'script[src]:not([integrity]):not([src^="http"]):not([src^="//"])'
},
files: {
'dest-index.html': 'source-index.html',
},
},
},
});
`
#### assetsDir
Defaults to ''.
`js
grunt.initConfig({
sri_hash: {
all: {
options: {
assetsDir: '_site'
},
files: {
'dest-index.html': 'source-index.html',
},
},
},
});
`
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
- See CHANGELOG.md` for release history