A Vite plugin that uses Content Identifiers (CID) as hashes for build assets, enabling true content-addressed immutable builds perfect for decentralized web deployment.
Tested Runtimes: Deno • Node.js • Bun • Cloudflare Workers • Browsers
- 🔒 Content Addressed: Files are named by their content hash (CID), ensuring true immutability
- ⚡️ Vite Powered: Seamless integration with Vite's build pipeline and development server
- 📦 IPFS Ready: Perfect for deploying to IPFS, Arweave, or any content-addressed storage
- 🔄 Automatic Updates: All references to renamed files are automatically updated
- 📝 Manifest Support: Generates updated manifest files with CID-based filenames
- 🎯 TypeScript: Written in TypeScript with full type definitions
import { cid } from "jsr:@fusionstrings/vite-plugin-cid";# Using JSR with npm
npx jsr add @fusionstrings/vite-plugin-cid
# Using JSR with pnpm
pnpm dlx jsr add @fusionstrings/vite-plugin-cid
# Using JSR with yarn
yarn dlx jsr add @fusionstrings/vite-plugin-cidAdd the plugin to your vite.config.ts:
import { defineConfig } from "vite";
import { cid } from "@fusionstrings/vite-plugin-cid";
export default defineConfig({
plugins: [
cid(),
],
build: {
manifest: true, // Optional: Generate manifest file
modulePreload: true, // Optional: Enable module preloading
},
});- During the build process, the plugin runs in the
generateBundlehook - Files are processed in topological order (dependencies first)
- Each file's content is hashed using the IPFS CID algorithm
- Files are renamed with their CID hash
- All references to renamed files are automatically updated in:
- JavaScript/CSS code
- HTML files
- Source maps
- Manifest files
The plugin works out of the box with no configuration required. Simply add it to your Vite plugins array.
Before:
dist/
assets/
index-a1b2c3d4.js
style-e5f6g7h8.css
After:
dist/
assets/
bafkreievmj4srvi27bv4qogei7yqihtcumxrmacteezcl4besq6strr44u.js
bafkreicdwt3ocjgrqc3nxzvitlterbgeem3hrpaudujvil3hkwhdcbcupm.css
The plugin supports Multi-Page Applications (MPA) by preserving HTML entry point filenames. This ensures that web servers can properly serve the application while all asset files use CID-based naming.
# Type check
deno check src/**/*.ts
# Format code
deno fmt
# Lint code
deno lint
# Run tests
deno test --allow-read --allow-write --allow-env
# Generate documentation
deno task docs# Create a new version tag
git tag v0.0.2
git push origin v0.0.2
# Publishes automatically to JSR via GitHub ActionsMIT