A Vite plugin that auto-generates Subresource Integrity (SRI) hashes for built assets and injects integrity/crossorigin attributes into HTML output. Current stable version 1.4.1, requires Node ≥18 and Vite ≥4. Released monthly. Key differentiators: supports multiple hash algorithms (sha256, sha384, sha512), optional lazy-loaded chunk integrity via runtime patch, Vite manifest augmentation for SSR/backend-owned HTML, configurable include/exclude patterns, and in-memory HTTP cache. ESM-only, builds on parse5 for HTML parsing. Does not work for most SSR frameworks unless pre-rendering HTML or reading the augmented manifest.
npm install vite-plugin-sri-genVerified import paths — ran on the pinned version, not inferred.
Shows basic setup of vite-plugin-sri-gen with custom algorithms, include/exclude patterns, and manifest enabled.
No action needed unless you extended the plugin; the public API is unchanged.
Set verboseLogging: true in config if you rely on old logging output.
Use dynamic import() or switch to ESM in your project.
Pre-render your SSR application (e.g., using vite-plugin-ssr pre-rendering) or use the manifest augmentation (enableManifest: true) to attach SRI server-side.
Update to v1.3.2 or later; for older versions, ensure resources use relative paths.
Add build: { manifest: true } to your Vite config.Change to ESM: set "type": "module" in package.json or use dynamic import().
Use import { sriGen } from 'vite-plugin-sri-gen' or default import sriGen from 'vite-plugin-sri-gen'.Ensure your build produces HTML files, or enable enableManifest and set build.manifest: true to use the manifest approach.
Ensure that no other plugins modify the resource content after sriGen runs; reorder plugins or disable conflicting transforms.