Registry / devops / vite-plugin-long-term-cache-import-map

vite-plugin-long-term-cache-import-map

JSON →
library0.2.6jsnpmunverified

A Vite plugin enabling long-term caching of static assets (JS, CSS) using import maps. Version 0.2.6, actively maintained with weekly releases. Key differentiators: it generates and patches import maps to decouple file hashes from URLs, allowing aggressive caching without cache invalidation. Unlike standard Vite hashing, this plugin splits import map management into generator and patcher plugins, giving fine-grained control over entry points and chunk names. Useful for projects needing maximal cache hit rates, especially with large vendor chunks like monaco-editor.

npm install vite-plugin-long-term-cache-import-map
INSTALL
IMPORT
SIG · VITE-PLUGIN-LONG-T
V
vite-plugin-long-term-cache-import-map
devopsjavascriptv0.2.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

importMapGeneratorPlugin
import { importMapGeneratorPlugin } from 'vite-plugin-long-term-cache-import-map'
const importMapGeneratorPlugin = require('vite-plugin-long-term-cache-import-map')
ESM-only package; named export, not default.
importMapPatcherPlugin
import { importMapPatcherPlugin } from 'vite-plugin-long-term-cache-import-map'
import importMapPatcherPlugin from 'vite-plugin-long-term-cache-import-map'
Named export, not default. Do not treat as default import.
ImportMapGeneratorOptions
import type { ImportMapGeneratorOptions } from 'vite-plugin-long-term-cache-import-map'
const ImportMapGeneratorOptions = require('vite-plugin-long-term-cache-import-map').ImportMapGeneratorOptions
TypeScript type export for generator options; use type import.

Configures Vite with import map caching plugins, generating and patching import maps for long-term cache.

import { defineConfig } from 'vite'; import Vue from '@vitejs/plugin-vue'; import { importMapGeneratorPlugin, importMapPatcherPlugin } from 'vite-plugin-long-term-cache-import-map'; export default defineConfig({ plugins: [ Vue(), importMapGeneratorPlugin(), importMapPatcherPlugin({ entryPath: '/assets/js/index.js' }), ], build: { rollupOptions: { output: { entryFileNames: 'assets/js/[name].js', chunkFileNames: 'assets/js/[name].js', assetFileNames: (info) => { if (info.name.endsWith('.css')) return 'assets/css/[name]-[hash].[ext]'; return 'assets/[ext]/[name].[ext]'; }, manualChunks: (id) => { if (id.includes('node_modules')) { if (id.includes('monaco-editor')) return 'vendor-monaco-editor'; if (id.includes('@codemirror')) return 'vendor-codemirror'; return 'vendor-common'; } return 'main-all'; }, }, }, }, });
Debug
Known issues
gotchaChunk filenames must NOT include hashes when using import map patcher; hashes are managed by the plugin.
fix
Set output.entryFileNames and output.chunkFileNames without [hash] (e.g., 'assets/js/[name].js').
affects: >=0.1.0
gotchaManual chunk splitting can cause white screen or JS errors if not thoroughly tested; the plugin's import map may not cover all chunks correctly.
fix
Test all pages after adding manualChunks; ensure all entry points are covered by importMapPatcherPlugin options.
affects: >=0.1.0
deprecatedImport map patcher configuration may change in future versions; current API uses entryPath string but might shift to more flexible options.
fix
Monitor GitHub for API updates; consider pinning version if stability is critical.
affects: 0.2.x
gotchaCSS assets must be named with hashes (e.g., [hash]) because import maps do not cover CSS; the example in README handles this conditionally.
fix
Use assetFileNames function to add [hash] only for .css files (and other non-JS assets if needed).
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'vite-plugin-long-term-cache-import-map'
Missing or incorrect installation (npm vs pnpm vs yarn).
fix
Run `npm install vite-plugin-long-term-cache-import-map --save-dev` or equivalent for your package manager.
The requested module 'vite-plugin-long-term-cache-import-map' does not provide an export named 'default'
Using default import instead of named imports.
fix
Use `import { importMapGeneratorPlugin, importMapPatcherPlugin } from 'vite-plugin-long-term-cache-import-map'`.
TypeError: importMapPatcherPlugin is not a function
Probably imported incorrectly (e.g., as default or misspelled).
fix
Ensure correct named import: `import { importMapPatcherPlugin } from 'vite-plugin-long-term-cache-import-map'`.
Error: entryPath must be a string
importMapPatcherPlugin options missing or invalid entryPath.
fix
Pass object with `entryPath` property: `importMapPatcherPlugin({ entryPath: '/assets/js/index.js' })`.
Upgrade
Version history
0.2.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
vite-plugin-long-term-cache-import-map — npm install vite-plugin-long-term-cache-import-map · libregistry