Webpack plugin for enabling Subresource Integrity (SRI) to protect against compromised CDN resources. Current stable version is 5.1.0, with release candidate 5.2.0-rc.1 available. The plugin supports Webpack 5.12+ and html-webpack-plugin 5+, and now provides an ES module distribution alongside CommonJS. Key differentiators include integration with html-webpack-plugin for automatic integrity injection, lazy hash loading option for larger projects, and TypeScript type definitions.
npm install webpack-subresource-integrityVerified import paths — ran on the pinned version, not inferred.
Minimal webpack config to enable SRI for all scripts and styles, with cross-origin loading and content hashing.
Change import from default to named import: import { SubresourceIntegrityPlugin } from 'webpack-subresource-integrity'.Use enabled: 'auto' (default) or omit the option to avoid issues in development.
Upgrade to v5 and follow migration guide in MIGRATE-v1-to-v5.md.
Ensure all assets are processed by webpack or handle errors appropriately.
Upgrade to supported versions.
Test with your project; if hash duplication is not acceptable, use default hash loading.
Replace 'const SubresourceIntegrityPlugin = require("webpack-subresource-integrity")' with 'const { SubresourceIntegrityPlugin } = require("webpack-subresource-integrity")'.Install html-webpack-plugin >=5.0.0-beta.1 and add it to webpack plugins.
Ensure all assets are processed by webpack loaders, or exclude non-SRI assets using plugin options.
Upgrade to Webpack >=5.12.0 and html-webpack-plugin >=5.0.0-beta.1.