A Vite plugin (v0.1.0) that generates an import map JSON virtual module, enabling sharing of dependencies without duplication. It allows mapping local modules (e.g., React) to custom re-export files to support named imports from CJS packages, and external URLs (e.g., from esm.sh) to avoid bundling. Unlike Module Federation or @originjs/vite-plugin-federation, this plugin focuses solely on import maps with fine-grained control over local and remote mappings. Actively maintained on GitHub, with TypeScript definitions provided. Peer dependency on Vite (*).
npm install importmap-vite-pluginVerified import paths — ran on the pinned version, not inferred.
Configures the Vite plugin with custom local mappings, creates re-export modules for CJS packages, and mounts the generated import map in the HTML.
Create a wrapper module (e.g., 'src/import-map/react.js') that imports the CJS default and re-exports named members
Use es-module-shims or another import map polyfill for older browsers
In production builds, the plugin still works; just ensure your deployment serves the import map JSON correctly (injected via script tag)
Test external URLs manually; ensure they export the symbols you need and are CORS-compatible
Create a wrapper file like 'src/import-map/react.js' that re-exports named members from the CJS default export
Add a type declaration file: declare module 'virtual:importmap' { const map: { imports: Record<string, string> }; export default map; }Change imports from an array to an object with module names as keys
No dependency data recorded yet.