Registry / devops / vite-plugin-externalize-dependencies

vite-plugin-externalize-dependencies

JSON →
library1.0.1jsnpmunverified

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-dependencies
INSTALL
IMPORT
SIG · VITE-PLUGIN-EXTERN
V
vite-plugin-externalize-dependencies
devopsjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

externalize
import externalize from 'vite-plugin-externalize-dependencies'
import { externalize } from 'vite-plugin-externalize-dependencies'
Default export; named import will result in undefined.
ExternalizeOptions
import type { ExternalizeOptions } from 'vite-plugin-externalize-dependencies'
import { ExternalizeOptions } from 'vite-plugin-externalize-dependencies'
Type-only export for TypeScript.
externalize (CommonJS)
const externalize = require('vite-plugin-externalize-dependencies')
const { externalize } = require('vite-plugin-externalize-dependencies')
Default CommonJS export; destructuring fails.

Basic setup: import default function, pass externals array with name, regex, and function matchers.

// vite.config.ts import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ externalize({ externals: [ 'react', /^external-.*/, (moduleName) => moduleName.includes('external'), ], }), ], }); // Import function import externalize from 'vite-plugin-externalize-dependencies';
Debug
Known issues
breakingSince v1.0.0, the plugin now accounts for Vite's base path config, which may change the externalized module's URL in the browser.
fix
Ensure your project uses Vite's base path correctly; the plugin will prepend it to externalized module requests.
affects: >=1.0.0
gotchaThe plugin is designed for development only. In production, you must manually configure build.rollupOptions.external in Vite; this plugin does not handle production builds.
fix
For production builds, add externalized modules to build.rollupOptions.external in your Vite config.
affects: >=0.0.0
breakingSince v0.11.0, the plugin automatically externalizes all subexports of a module when the module name is matched by exact string. For example, externalizing 'react' now also externalizes 'react/jsx-runtime'.
fix
If you only want to externalize the exact module and not its subexports, use a custom function to filter subexports.
affects: >=0.11.0
gotchaThe plugin suppresses certain Vite errors/warnings for externalized modules (e.g., 'cannot be marked as external'). If you see unexpected missing dependencies, check that the module is correctly externalized.
fix
Verify the externals list; if a module is incorrectly externalized, it will not be bundled. Use the plugin's logging if available.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'vite-plugin-externalize-dependencies' or its corresponding type declarations
Missing installation or incorrect TypeScript configuration.
fix
Run `npm i vite-plugin-externalize-dependencies --save-dev` and ensure your tsconfig includes 'node_modules/@types'.
The requested module 'vite-plugin-externalize-dependencies' does not provide an export named 'externalize'
Trying to import a named export instead of default export.
fix
Use default import: `import externalize from 'vite-plugin-externalize-dependencies'`
TypeError: externalize is not a function
If using CommonJS via require and destructuring, externalize might be undefined.
fix
Use `const externalize = require('vite-plugin-externalize-dependencies')` without destructuring.
Warning: The entry point 'moduleName' cannot be marked as external
This warning is intentionally suppressed by the plugin; it's not an error. If you see it, the plugin may not be loaded or working.
fix
Ensure the plugin is added to the Vite plugins array and that the module is in the externals list.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
viterequiredThe plugin is intended to be used as a Vite plugin and requires Vite's build system.
Agent activity
4 hits · last 30 days
node
4
Resources
vite-plugin-externalize-dependencies — npm install vite-plugin-externalize-dependencies · libregistry