{"id":22657,"library":"vite-plugin-externalize-dependencies","title":"vite-plugin-externalize-dependencies","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/MilanKovacic/vite-plugin-externalize-dependencies","tags":["javascript","vite","vite-plugin","externalize-dependencies","bundle-exclusion","import-maps","webpack-externals","rollup-externals","dependency-management","typescript"],"install":[{"cmd":"npm install vite-plugin-externalize-dependencies","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-externalize-dependencies","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-externalize-dependencies","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The plugin is intended to be used as a Vite plugin and requires Vite's build system.","package":"vite","optional":false}],"imports":[{"note":"Default export; named import will result in undefined.","wrong":"import { externalize } from 'vite-plugin-externalize-dependencies'","symbol":"externalize","correct":"import externalize from 'vite-plugin-externalize-dependencies'"},{"note":"Type-only export for TypeScript.","wrong":"import { ExternalizeOptions } from 'vite-plugin-externalize-dependencies'","symbol":"ExternalizeOptions","correct":"import type { ExternalizeOptions } from 'vite-plugin-externalize-dependencies'"},{"note":"Default CommonJS export; destructuring fails.","wrong":"const { externalize } = require('vite-plugin-externalize-dependencies')","symbol":"externalize (CommonJS)","correct":"const externalize = require('vite-plugin-externalize-dependencies')"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nexport default defineConfig({\n  plugins: [\n    externalize({\n      externals: [\n        'react',\n        /^external-.*/,\n        (moduleName) => moduleName.includes('external'),\n      ],\n    }),\n  ],\n});\n\n// Import function\nimport externalize from 'vite-plugin-externalize-dependencies';","lang":"typescript","description":"Basic setup: import default function, pass externals array with name, regex, and function matchers."},"warnings":[{"fix":"Ensure your project uses Vite's base path correctly; the plugin will prepend it to externalized module requests.","message":"Since v1.0.0, the plugin now accounts for Vite's base path config, which may change the externalized module's URL in the browser.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For production builds, add externalized modules to build.rollupOptions.external in your Vite config.","message":"The plugin is designed for development only. In production, you must manually configure build.rollupOptions.external in Vite; this plugin does not handle production builds.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"If you only want to externalize the exact module and not its subexports, use a custom function to filter subexports.","message":"Since 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'.","severity":"breaking","affected_versions":">=0.11.0"},{"fix":"Verify the externals list; if a module is incorrectly externalized, it will not be bundled. Use the plugin's logging if available.","message":"The 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.","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":"Run `npm i vite-plugin-externalize-dependencies --save-dev` and ensure your tsconfig includes 'node_modules/@types'.","cause":"Missing installation or incorrect TypeScript configuration.","error":"Cannot find module 'vite-plugin-externalize-dependencies' or its corresponding type declarations"},{"fix":"Use default import: `import externalize from 'vite-plugin-externalize-dependencies'`","cause":"Trying to import a named export instead of default export.","error":"The requested module 'vite-plugin-externalize-dependencies' does not provide an export named 'externalize'"},{"fix":"Use `const externalize = require('vite-plugin-externalize-dependencies')` without destructuring.","cause":"If using CommonJS via require and destructuring, externalize might be undefined.","error":"TypeError: externalize is not a function"},{"fix":"Ensure the plugin is added to the Vite plugins array and that the module is in the externals list.","cause":"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.","error":"Warning: The entry point 'moduleName' cannot be marked as external"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}