A Vite plugin (v0.2.2) that resolves external dependencies by mapping import specifiers to global variables or custom code snippets. It allows configuring external mappings via plugin options or Vite's resolve.externals configuration. Useful for replacing Node.js or client-side libraries with CDN scripts in Vite projects. It supports both simple global mappings and advanced code generation for scoped exports. No recent updates; stable but minimal feature set compared to alternatives like rollup-plugin-external-globals. Suitable for small to medium projects needing quick externals resolution.
npm install vite-plugin-resolve-externalsVerified import paths — ran on the pinned version, not inferred.
Basic setup: map 'vue' to global 'Vue', 'vue-router' to 'VueRouter', 'axios' to 'axios' in Vite project.
Prefer passing externals as the first argument to resolveExternalsPlugin() instead of using resolve.externals in Vite config.
Wrap custom exports in a function that returns a template literal. Test by building with --debug flag.
Move externals from resolve.externals to the plugin call: resolveExternalsPlugin({...})Pass externals as argument to resolveExternalsPlugin().
Ensure the global is available in the browser before the script runs, e.g., via CDN script tags.
Install as devDependency: npm install -D vite-plugin-resolve-externals
Use 'import resolveExternalsPlugin from ...' or 'import * as pkg from ...; pkg.default(...)'
Replace require() with import or use dynamic import: const resolve = (await import(...)).default
Pass externals directly to resolveExternalsPlugin() as the first argument.