grunt-sri-hash
v1.1.5
Published
A grunt task which hashes all scripts and stylesheets with integrity attributes.
Downloads
390
Maintainers
Readme
grunt-sri-hash
A grunt task which hashes all scripts and stylesheets with integrity attributes.
Getting Started
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:
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:
grunt.loadNpmTasks('grunt-sri-hash');
The "sri_hash" task
Overview
In your project's Gruntfile, add a section named sri_hash
to the data object passed into grunt.initConfig()
.
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',
},
},
},
});
Options
algorithm
Defaults to sha384
.
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^="//"])
.
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 ''
.
grunt.initConfig({
sri_hash: {
all: {
options: {
assetsDir: '_site'
},
files: {
'dest-index.html': 'source-index.html',
},
},
},
});
Contributing
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.
Release History
- See
CHANGELOG.md
for release history