Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

vite-plugin-html-sri

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-html-sri

A Vite plugin that enables Subresource Integrity (SRI) by adding integrity attributes to JavaScript and CSS assets

Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

vite-plugin-html-sri

Subresource Integrity (SRI) is a security feature that helps ensure resources fetched by your website are delivered without unexpected manipulation. It uses integrity hashes that browsers verify before loading the resources.

  • ⚡️ Adds subresource integrity at build time
  • 📦 Automatically adds integrity hashes for both local assets (JavaScript and CSS files) and external resources (e.g., CDN links)
  • 🔒 Enhanced security
  • 🔌 Easy integration

Vite, by default, does not provide support for Subresource Integrity (SRI). This plugin automatically generates integrity hashes for both local and external assets by transforming the html files.

💿 Installation

Install the package as a devDependency

yarn add vite-plugin-html-sri -D

🚀 Usage

❗ Note: Integrity hashes are only added to resources that do not already have an existing integrity attribute.

# vite.config.js
import { defineConfig } from 'vite';
import sri from 'vite-plugin-html-sri';

export default defineConfig({
  plugins: [
    sri(),
  ],
})

Options

This plugin offers the following optional options:

# Choose which algorithm to use for creating integrity hashes
algorithm: 'sha256' | 'sha384' | 'sha512'  # default is 'sha384'

# Enable or disable adding integrity hashes to external assets
external: boolean  # default is true

License

MIT © Duc Phung

If you find this project interesting or helpful, I'd love your support! Please consider giving it a star (⭐) and following me on GitHub.

I love coding and always have new ideas, so stay tuned—your support won’t be in vain!

Keywords

subresource

FAQs

Package last updated on 25 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts