1.1.5 • Published 5 years ago

grunt-sri-hash v1.1.5

Weekly downloads
24
License
MIT
Repository
github
Last release
5 years ago

grunt-sri-hash

Greenkeeper badge Build Status Dependency Status devDependency Status npm Version npm Downloads

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
1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago