Gathering detailed insights and metrics for vite-plugin-sri4
Gathering detailed insights and metrics for vite-plugin-sri4
Gathering detailed insights and metrics for vite-plugin-sri4
Gathering detailed insights and metrics for vite-plugin-sri4
License A Vite plugin to generate Subresource Integrity (SRI) hashes for your assets during the build process.
npm install vite-plugin-sri4
Typescript
Module System
Node Version
NPM Version
JavaScript (98.81%)
HTML (0.66%)
CSS (0.53%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
70 Commits
1 Watchers
7 Branches
1 Contributors
Updated on Jul 02, 2025
Latest Version
3.0.0
Package Id
vite-plugin-sri4@3.0.0
Unpacked Size
30.74 kB
Size
6.80 kB
File Count
4
NPM Version
10.8.2
Node Version
18.20.8
Published on
Jul 02, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
1
A Vite plugin to generate Subresource Integrity (SRI) hashes for your assets during the build process. This plugin computes SRI hashes for JavaScript and CSS files and injects them as integrity
and crossorigin="anonymous"
attributes into your HTML, ensuring your resources have not been tampered with when loaded by browsers.
sha384
).integrity
and crossorigin
attributes into <script>
and <link>
tags in your HTML.Access-Control-Allow-Origin
.1npm install vite-plugin-sri4 --save-dev
Add the plugin to your Vite configuration by updating your vite.config.js or vite.config.ts file:
1// vite.config.js 2import { defineConfig } from 'vite'; 3import sri from 'vite-plugin-sri4'; 4 5export default defineConfig({ 6 plugins: [ 7 sri({ 8 // Optional. The security hash algorithm. Defaults to "sha384". 9 algorithm: 'sha384', 10 // Optional. Domains to bypass SRI injection. 11 bypassDomains: ['example.com'], 12 // Optional. Suppress warnings for missing assets. 13 ignoreMissingAsset: false, 14 // Optional. Enable debug logging. 15 debug: false 16 }) 17 ] 18});
Input:
1<script src="app.js"></script> 2<link rel="stylesheet" href="style.css">
Output:
1<script src="app.js" integrity="sha384-..." crossorigin="anonymous"></script> 2<link rel="stylesheet" href="style.css" integrity="sha384-..." crossorigin="anonymous">
algorithm
(string):
The hash algorithm used for computing SRI. Default is sha384. You may change it to other supported algorithms like sha256.bypassDomains
(ArrayignoreMissingAsset
(boolean):
When true, suppresses warnings for assets that are not found in the bundle. Default is false.debug
(boolean):
When true, enables detailed debug logging. Default is false.The plugin includes an example project in the example
directory that demonstrates its usage with a simple Vite application. To try it:
1npm install 2cd example 3npm install
1npm run build
dist/index.html
to see the SRI hashes in actionThe example project shows:
Hash Algorithm Selection
sha384
(default) for a good balance of security and performancesha512
for maximum securitysha1
as it's considered cryptographically weakCORS Configuration
Access-Control-Allow-Origin
headersbypassDomains
for trusted domains that don't support CORSPerformance Optimization
ignoreMissingAsset
in development for faster buildsSecurity Considerations
Missing Integrity Attributes
CORS Errors
bypassDomains
if neededBuild Performance
ignoreMissingAsset
if you have many external resourcesEnable debug mode to see detailed logs:
1sri({ 2 debug: true 3})
This will show:
We welcome contributions! Here's how you can help:
git checkout -b feature/my-feature
git commit -am 'Add some feature'
git push origin feature/my-feature
Please make sure to:
This project was inspired by vite-plugin-sri3, which provides subresource integrity for Vite. We've built upon its foundation to create an enhanced version with additional features and improved compatibility.
Other projects that influenced this work:
This project is licensed under the MIT License - see the LICENSE file for details.
No vulnerabilities found.
No security vulnerabilities found.