A Rollup plugin that adds Subresource Integrity (SRI) attributes to HTML files to ensure the integrity of scripts and stylesheets using hashing algorithms like SHA-256, SHA-384, and SHA-512.
npm install @darcas/rollup-sub-resource-integrity!NPM Last Update
!NPM Version
!NPM Downloads
!NPM License
SubResourceIntegrity is a Rollup plugin that adds Subresource Integrity (SRI) attributes to your HTML files. SRI helps ensure the integrity of your external resources (e.g., scripts and stylesheets) by allowing browsers to verify that the fetched files are delivered without unexpected manipulation.
- Automatically calculates integrity hashes for resources .htm. and .html.
- Supports multiple hashing algorithms (sha256, sha384, sha512).
- Integrates seamlessly into the Rollup build process.
To use this plugin, install it via npm:
``bash`
npm i -D @darcas/rollup-sub-resource-integrity
Or, if you're using yarn:
`bash`
yarn add @darcas/rollup-sub-resource-integrity --dev
In your vite.config.mts just add:
`ts
import SubResourceIntegrity from '@darcas/rollup-sub-resource-integrity';
import { defineConfig } from 'vite';
export default defineConfig({
//..
plugins: [
//..
SubResourceIntegrity('sha384'),
//..
],
//..
});
`
1. During the writeBundle phase, the plugin reads the HTML files in the output directory.
2. It scans for resource tags (