@jdx-plugins/web-importmap-loader
v0.1.0
Published
Smart runtime import map loader with caching, wildcard support, and multi-map merging.
Maintainers
Readme
🚀 Import Map Loader
A tiny utility to load, merge, cache, and extend Import Maps at runtime.
Supports:
- ✅ Multiple import maps
- ✅ LocalStorage caching
- ✅ Versioned cache invalidation
- ✅ Wildcard (
*) import support - ✅ Automatic DOM injection
📦 Installation
Using NPM
npm install importmap-loaderOr use directly in browser
<script type="module" src="./loadImportMaps.js"></script>🚀 Quick Start
1. Import the loader
import { loadImportMaps } from "importmap-loader";2. Load your import maps
await loadImportMaps({
maps: [
"/importmap.json",
"/vendor.importmap.json"
],
version: "1"
});📂 Example Import Map
importmap.json
{
"imports": {
"react": "https://esm.sh/react",
"lib/*": "/js/lib/*"
}
}✨ Wildcard Support
You can define wildcard paths:
{
"imports": {
"utils/*": "/src/utils/*"
}
}Then this works:
import { helper } from "utils/helper.js";Automatically resolves to:
/src/utils/helper.js💾 Cache System
Import maps are cached inside:
localStorageKey format:
__importmap_cache__:<url>:<version>🔄 Force Cache Refresh
Just bump the version:
await loadImportMaps({
maps: ["/importmap.json"],
version: "2"
});⚙️ How It Works
- Fetch all import map files
- Merge imports & scopes
- Resolve wildcard rules
- Inject
<script type="importmap"> - Cache results
🧩 Full Example
<script type="module">
import { loadImportMaps } from "./loadImportMaps.js";
await loadImportMaps({
maps: ["/importmap.json"]
});
const { default: app } = await import("app/main.js");
</script>⚠️ Important Notes
- Must be called before any module imports
- Requires browser with Import Maps support
- Works best in modern Chromium browsers
📜 License
Apache 2.0 License
❤️ Why This Exists
Managing multiple import maps and cache invalidation manually is painful.
This loader makes it:
- simple
- fast
- scalable
- production-ready
⭐ Contributing
PRs are welcome!
If you find a bug or want a feature:
- Open an issue
- Fork the repo
- Submit a PR 🚀
