{"id":22846,"library":"vite-plugin-sri","title":"vite-plugin-sri","description":"A Vite plugin that adds Subresource Integrity (SRI) hashes to script and stylesheet imports in index.html at build time. Version 0.0.2 is current. Forked from @small-tech/vite-plugin-sri to fix an issue where dynamic imports were not handled correctly. Unlike the original, this plugin processes assets after Vite's build transformation, ensuring correct integrity hashes for dynamically imported modules. Released under ISC license.","status":"active","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/JonathanLee-LX/vite-plugin-sri","tags":["javascript","Vite","Subresource","Integrity","SRI","plugin"],"install":[{"cmd":"npm install vite-plugin-sri","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-sri","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-sri","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required to function as a Vite plugin","package":"vite","optional":false}],"imports":[{"note":"ESM-only; no named export, default export only","wrong":"const sri = require('vite-plugin-sri')","symbol":"sri","correct":"import sri from 'vite-plugin-sri'"},{"note":"Vite's utility for config, not part of this plugin but commonly used together","wrong":null,"symbol":"defineConfig","correct":"import { defineConfig } from 'vite'"},{"note":"sri is a function that returns a plugin object, not a class","wrong":"plugins: [new sri()]","symbol":"sri()","correct":"plugins: [sri()]"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport sri from 'vite-plugin-sri';\n\nexport default defineConfig({\n  plugins: [sri()]\n});","lang":"javascript","description":"Minimal Vite config to enable SRI hashing on all script and stylesheet imports."},"warnings":[{"fix":"Run `npx vite build` to generate SRI-enabled output.","message":"Only affects build output, not dev server. SRI hashes are only added during production builds.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure this plugin is placed after any plugins that modify script/style paths.","message":"Plugin may not work if Vite's renderBuiltUrl or other asset manipulation hooks alter script/src attributes after plugin runs.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use same build artifacts for both hash computation and deployment.","message":"Integrity hashes are computed based on the final built file content; if files are served from a CDN, ensure the CDN serves the exact same file or the hash will mismatch.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Upgrade Vite to version 2.0.0 or later, or downgrade the plugin if possible.","cause":"Installing plugin with an older Vite version that does not support the required hooks.","error":"Error: The plugin 'vite-plugin-sri' requires Vite >=2.0.0"},{"fix":"Use `import sri from 'vite-plugin-sri'` (default import).","cause":"Using named import instead of default import or using CommonJS require incorrectly.","error":"TypeError: sri is not a function"},{"fix":"Rebuild the project to regenerate hashes based on current file content.","cause":"The computed hash does not match the integrity attribute in the HTML, likely due to content changes after build.","error":"Error: Integrity mismatch for 'app.js'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}