npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sri-stats-webpack-plugin

v0.7.3

Published

Subresource integrity hash generator plugin for webpack.

Downloads

437

Readme

sri-stats-webpack-plugin

npm version Build Status Dependency Status devDependency Status

Most of the code based on @roman01la's webpack-sri.

This is a webpack plugin which generates a subresource integrity hash. It adds the hash to webpack's stats object.

It creates a direct mapping with [asset] => sri hash, and another mapping of [asset] => { [integrityKey]: hash }.

The direct mapping is saved into webpack's compilation, while the secondary mapping is saved into stats.toJson().

Example:

// webpack stats

compilation.getStats().toJson().sris
# => {
  'main-459130c16ce3c68b595e.js': {
    integrity: 'sha384-Lgg9yFvipJWo8BEZOJhBN2wCPtr/RVl9EWeXFHUzQKtUduAyATSIl79NJbfzZT8p'
  }
}

// webpack compilation

compilation.__RESULTS_SRIS
# => {
  'main-459130c16ce3c68b595e.js': 'sha384-Lgg9yFvipJWo8BEZOJhBN2wCPtr/RVl9EWeXFHUzQKtUduAyATSIl79NJbfzZT8p'
}

Setup

npm install sri-stats-webpack-plugin --save-dev

Usage

// Your webpack config

var path = require('path');
var SriStatsPlugin = require('sri-stats-webpack-plugin');

var config = {
  plugins: [
    new SriStatsPlugin({
      algorithm: 'sha512',
      allow: (/\.(js|css)$/i/),
      customStatsKey: 'rails',
      assetKey: 'integrity',
      saveAs: path.join(__dirname, 'build', 'subresource-integrity-mapping.json'),
      write: true,
      writeDirectMapping: true,
      resultsKey: '__RESULTS_SRIS',
      runAfterEmit: true
    })
 ]
};

Configuration

  • algorithm: The hashing algorithm to use. Default: sha384
  • allow: This is a regex to allow what files should be hashed. The default regex is set to allow only .js or .css files. Default: /\.(js|css)$/i/
  • customStatsKey: This is the parent key the mapping is saved to. You will probably want to change this if you are using it with the SprocketsStatsWebpackPlugin. Default: sris
  • assetKey: This is the child key that the hash will be associated to. Default: integrity
  • saveAs: Absolute path to where to save the output to. Default: path.join(process.env.WEBPACK_OUTPUT_PATH, 'build', 'subresource-integrity-mapping.json'). If WEBPACK_OUTPUT_PATH, is not specified, it will fallback to process.cwd().
  • write: Boolean option, of whether to write the stats file or not. Default: false
  • writeDirectMapping: Boolean option, enables writing [asset] => [hash]. Otherwise it will write it as [asset] => { [integrityKey] => [hash] }. Default: true
  • resultsKey: Where to save the results to in webpack's compilation object. Default: __RESULTS_SRIS
  • runAfterEmit: Boolean option, whether to calculate hashes during or after emit stage. If HTMLWebpackPlugin is supposed to pick up the hashes (during emit stage), set to false and run this plugin first. Default: true

License

MIT.