Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including metalsmith-subresource-integrity with all npm packages installed. Try it out:

var metalsmithSubresourceIntegrity = require("metalsmith-subresource-integrity")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

metalsmith-subresource-integrity v1.0.0

Metalsmith plugin for adding subresource integrity


A Metalsmith plugin that adds a subresouce object to _metadata. This allows the user to look up the hash from within templates.


Example of setting up subresource integrity in code:

var metalsmith = require('metalsmith'),
  subresourceIntegrity = require('metalsmith-subresource-integrity');

  algorithm: 'sha512',
  pattern: '*.{css,js}',
  minimatchOptions: {
    matchBase: true

Example of setting up subresource integrity in config:

  "source": "src",
  "destination": "build",
  "plugins": {
    "metalsmith-subresource-integrity": {
      "algorithm": "sha512",
      "pattern": "*.{css,js}",
      "minimatchOptions": {
        "matchBase": true

In the template, a hash can be found like so (the example uses underscore templates):

  integrity="<%= subresource['css/main.css'] %>"

  integrity="<%= subresource['js/main.js'] %>"

Keep in mind that you will want to use this plugin after any file generation takes place (es6, coffeescript, sass) so the correct file names are found in the files list.



algorithm defaults to sha512. Can be either:

  • sha256
  • sha384
  • sha512

This is the hashing algorithm used.


pattern defaults to *.{css,js}. This is a minimatch pattern to determine the files to create subresource hashes for.


minimatchOptions defaults to {matchBase: true}. This is an Object of options for minimatch to tweak how pattern is applied.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free