A Vite plugin (v1.0.1) that allows you to exclude specific dependencies from the Vite bundle during development. It supports externalizing by exact module name, regex, or custom function, and automatically externalizes all subexports (e.g., react/jsx-runtime when 'react' is externalized). It also suppresses common Vite errors/warnings from externalized modules. The plugin is intended for development only; for production, users should configure build.rollupOptions.external manually. It ships TypeScript types and is actively maintained with regular releases.
npm install vite-plugin-externalize-dependenciesVerified import paths — ran on the pinned version, not inferred.
Basic setup: import default function, pass externals array with name, regex, and function matchers.
Ensure your project uses Vite's base path correctly; the plugin will prepend it to externalized module requests.
For production builds, add externalized modules to build.rollupOptions.external in your Vite config.
If you only want to externalize the exact module and not its subexports, use a custom function to filter subexports.
Verify the externals list; if a module is incorrectly externalized, it will not be bundled. Use the plugin's logging if available.
Run `npm i vite-plugin-externalize-dependencies --save-dev` and ensure your tsconfig includes 'node_modules/@types'.
Use default import: `import externalize from 'vite-plugin-externalize-dependencies'`
Use `const externalize = require('vite-plugin-externalize-dependencies')` without destructuring.Ensure the plugin is added to the Vite plugins array and that the module is in the externals list.