subresourceIntegrity(options?)
Computes Subresource Integrity for final local JS/CSS and updates HTML script, stylesheet, preload, and modulepreload tags.
ts
subresourceIntegrity({
algorithms: ["sha384", "sha512"],
crossorigin: "anonymous",
manifest: "meta/integrity.json",
strict: false,
});| Option | Default | Description |
|---|---|---|
algorithms | "sha384" | sha256 / sha384 / sha512; multiple digests supported |
filter | JavaScript and CSS | RegExp or (fileName, type) => boolean |
crossorigin | "anonymous" | anonymous / use-credentials; false disables automatic addition |
overwrite | true | Overwrite existing local integrity/crossorigin attributes |
manifest | false | true emits integrity-manifest.json; a string specifies a safe relative path |
strict | false | Fail the build when local scripts/styles cannot be matched to bundle output |
Full URLs count as local only when same-origin with an absolute base and under its path. Other remote assets are not downloaded or hashed. publicDir files are outside the bundle; include them in the graph or handle separately before enabling strict mode. Place before precompression even when used alone.
subresourceIntegrity Integrity
Generates SRI for final Vite JS/CSS and updates built HTML entries.
Runs late in output processing. Place before precompression so .gz/.br HTML matches the integrity-injected originals.
Signature
ts
export function subresourceIntegrity(options: SubresourceIntegrityPluginOptions = {}): Plugin;Example
ts
import { subresourceIntegrity } from "fast-vite-plugins";
const plugin = subresourceIntegrity({ algorithms: ["sha384"], manifest: "meta/integrity.json" });
export default { plugins: [plugin] };Input
| Input | Type | Required / default | Description |
|---|---|---|---|
options | SubresourceIntegrityPluginOptions | Optional; defaults to {} | Digest algorithms, asset filters, CORS, overwrite, manifest, and strict settings. |
Returns
| Value | Type | Description |
|---|---|---|
plugin | Plugin | Subresource Integrity plugin for Vite plugins. |
