Skip to content

Repository files navigation

vite-plugin-sri-gen

Add Subresource Integrity (SRI) hashes to your Vite build HTML output automatically.

NPM Version Build Status Test Results Code Coverage Known Vulnerabilities Known Vulnerabilities License

vite-plugin-sri-gen

Add Subresource Integrity (SRI) hashes to your Vite build automatically.

  • Adds integrity to scripts, stylesheets, and modulepreload links in emitted HTML — plus import map integrity, modulepreload injection for lazy chunks, a CSP-safe runtime for dynamic tags, and Vite manifest augmentation for backend-rendered HTML
  • Build-only by design — works out of the box for SPA, MPA, and prerendered SSG output
  • ESM-only, Node 18+, Vite 4+

Documentation

📚 Full documentation →

Install

npm i -D vite-plugin-sri-gen

Quick start

// vite.config.ts
import sri from "vite-plugin-sri-gen";

export default {
  plugins: [sri()],
};

That's it — every build gets SRI with sensible defaults. See the configuration reference for algorithm, crossorigin, skip patterns, and more.

Important

Pure SSR output (HTML rendered at request time) cannot be modified at build time. Prerendered HTML works normally, and backends that render their own HTML can consume SRI hashes from the augmented Vite manifest. Details: SSR, SSG & Prerendering.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for the fork/branch/PR workflow and the testing/linting expectations.

Security

See SECURITY.md for supported versions and how to report vulnerabilities.

License

MIT — see LICENSE.

About

A Vite plugin to auto-generate Subresource Integrity (SRI) hashes.

Topics

Resources

Contributing

Security policy

Stars

24 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages