A Vite plugin that automatically externalizes dependencies from your bundle during build, including subpath patterns. Current stable version is 0.10.0, released 2024-12-15. Supports Vite 2 through 7. Key differentiators: handles subpath exports, provides fine-grained control over which dependencies are externalized (deps, devDeps, peerDeps, optionalDeps, nodeBuiltins), and allows both inclusion and exception patterns via strings or regexes.
npm install vite-plugin-externalize-depsVerified import paths — ran on the pinned version, not inferred.
Add the plugin to vite.config.ts with default options. Externalizes all dependencies, peerDeps, optionalDeps, and node builtins; devDeps are bundled by default.
Upgrade plugin to v0.5.0 or later for Vite 4 compatibility, or use an older Vite.
Upgrade to v0.8.0+ for Vite 5.
Upgrade to v0.9.0+ for Vite 6.
Upgrade to v0.10.0+ for Vite 7.
Set `devDeps: true` in the plugin options to externalize devDependencies.
Use the `include` option (added in v0.7.0) to add packages to be externalized that are not automatically detected.
Omit `useFile` to let the plugin find package.json automatically, or keep it if you need a custom path.
Install the package as a dev dependency: npm install --save-dev vite-plugin-externalize-deps
Use `import { externalizeDeps } from 'vite-plugin-externalize-deps'` (curly braces).Remove `new` and call as `externalizeDeps()` directly.
Ensure `except` is an array: `except: ['package-name']`.