Automatic hashing
Every bundled asset referenced by your HTML gets its SHA-* hash computed at build time.
Security / Build Tooling
Automatically generate Subresource Integrity hashes for assets produced by your Rollup build.
The problem
Every <script> and <link> you ship is fetched over the network and executed by the browser — without any guarantee that the file it receives is the file you built.
Subresource Integrity closes that gap: the browser refuses to run a resource whose content doesn't match the hash you published alongside it.
// before
<script src="/assets/app.js"></script>x No integrity
// after
<script src="/assets/app.js"
integrity="sha384-V9kQ…"
crossorigin="anonymous"
></script>✓ Integrity verified
Background
Subresource Integrity (SRI) is a browser security feature that lets you pin a cryptographic hash to every resource you load. The hash travels in the integrity attribute of the tag; before executing a script or applying a stylesheet, the browser hashes what it downloaded and compares it with what you declared.
If the two don't match — because the file was tampered with, corrupted, or served from an unexpected source — the browser blocks it. Nothing runs, nothing leaks.
It is the standard defense against compromised CDNs and man-in-the-middle modifications of third-party code. Read more on MDN.
How it works
Rollup builds your assets exactly as it normally would.
The plugin reads each asset from the bundle and calculates its cryptographic hash.
Every emitted HTML file receives the integrity attribute on its matching tags.
The browser verifies each resource against its hash before executing it.
Before / After
The same HTML file, before and after the plugin runs. No hand-edited hashes, no drift between builds.
✕ Without Rollup SRI
<script type="module"
src="/assets/index-abc123.js"
></script>✕ Browser trusts the response blindly
✓ With Rollup SRI
<script type="module"
src="/assets/index-abc123.js"
integrity="sha384-V9kQ…"
crossorigin="anonymous"
></script>✓ Hash added automatically at build time
Features
Every bundled asset referenced by your HTML gets its SHA-* hash computed at build time.
A standard Rollup plugin that hooks into generateBundle — no extra build steps or wrappers.
Hashes are recalculated on every build. They can never drift from the assets they describe.
Works with hashed filenames, code splitting and multi-page setups out of the box.
Adds crossorigin="anonymous" alongside integrity so the browser verification actually applies.
One import, one call. Choose sha256, sha384 or sha512 — the default is sha384.
Usage
Import the plugin and add it to your plugin list. That's the entire configuration.
$ npm i -D @darcas/rollup-sub-resource-integrityimport { defineConfig } from 'vite'
import SubResourceIntegrity from '@darcas/rollup-sub-resource-integrity'
export default defineConfig({
plugins: [
SubResourceIntegrity(),
],
})By default the plugin uses sha384. Pass 'sha256' or 'sha512' to choose a different algorithm.
Generated output
<script type="module"
src="/assets/app-C8k92x.js"
integrity="sha384-V9kQ…SaWq"
crossorigin="anonymous"
></script>Developer experience
Add integrity verification to your build without introducing another complex workflow.
Manual workflow
With Rollup SRI
The plugin removes repetitive security-related build work — permanently.
Compatibility
A single peer dependency on Rollup itself. Vite projects work too, since Vite uses Rollup for production builds.
Security
Expected resource — declared in HTML
sha384-V9kQ3mZxL8fJ…Downloaded resource — hashed by the browser
sha384-V9kQ3mZxL8fJ…Browser verification — hash comparison
MATCH → executes
MISMATCH → blocked
Open source
The full source is public and MIT licensed. Issues, discussions and pull requests are welcome.
Install Rollup Subresource Integrity and let your build handle the hashes for you.