{"id":22707,"library":"vite-plugin-importmap","title":"vite-plugin-importmap","description":"Vite plugin (v0.1.1) that enables import map-like path resolution by environment variable (mark). Allows conditional module replacement per build target using string suffix conventions, arrays, or JSON config files. Unlike standard Vite resolve aliases, it switches between file variants based on a single mark. Minimal API surface, ESM-only, ships TypeScript definitions. Release cadence is low; single maintainer. Suitable for multi-tenant or configurable builds.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/yuexiaoliang/vite-plugin-importmap","tags":["javascript","vite","vite-plugin","importmap","typescript"],"install":[{"cmd":"npm install vite-plugin-importmap","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-importmap","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-importmap","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export; ESM-only. CJS require() will fail.","wrong":"const importmap = require('vite-plugin-importmap')","symbol":"importmap","correct":"import importmap from 'vite-plugin-importmap'"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport importmap from 'vite-plugin-importmap';\n\nconst mark = process.env.VITE_OPEN_TYPE ?? 'v1';\n\nexport default defineConfig({\n  plugins: [importmap(mark)]\n});\n","lang":"javascript","description":"Configures vite-plugin-importmap with an environment-based 'mark' to switch resolved file variants."},"warnings":[{"fix":"Set VITE_OPEN_TYPE environment variable or pass a string directly to importmap().","message":"mark must be set at build time; missing env variable reverts to original import path without transformation.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use static imports; avoid dynamic import() for variant switching.","message":"Plugin does not support dynamic imports or import() expressions; only static import/require statements are transformed.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure file variants match the pattern: baseName.<variant>.ext for string mode, or baseName[v1,v2].ext for array mode.","message":"File resolution relies on exact suffixes; mismatched naming conventions (e.g., case sensitivity) will not be resolved.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change to `import importmap from 'vite-plugin-importmap'` and ensure vite.config.js uses ESM or type: module in package.json.","cause":"Using CommonJS require() instead of ESM import.","error":"TypeError: importmap is not a function"},{"fix":"Call `importmap(mark)` with a string argument; e.g., `importmap('v1')`.","cause":"Calling importmap() without parentheses or passing invalid argument.","error":"[vite] The plugin 'vite-plugin-importmap' didn't output a plugin object."},{"fix":"Ensure the variant file exists with the correct naming pattern (e.g., test.v1.js) or adjust the mark value.","cause":"mark is set but no matching file variant exists (e.g., test.v1.js not found).","error":"Module not found: Can't resolve 'test.v1.js'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}