vite-plugin-externalize-deps
A configurable Vite plugin to help externalize your dependencies (including subpaths).
Getting Started
Install the package as a dev dependency.
npm install --save-dev vite-plugin-externalize-deps
pnpm install --save-dev vite-plugin-externalize-deps
yarn add --dev vite-plugin-externalize-deps
Add the plugin to your vite.config.ts
file.
import { defineConfig } from 'vite'
import { externalizeDeps } from 'vite-plugin-externalize-deps'
export default defineConfig({
plugins: [
externalizeDeps(),
],
})
Configuration
Pass an object to externalizeDeps
to override the default configuration.
externalizeDeps({
deps: true,
devDeps: false,
except: [],
nodeBuiltins: true,
optionalDeps: true,
peerDeps: true,
useFile: join(process.cwd(), 'package.json'),
})
To include specific dependencies in your bundle, you can add exceptions with the except
option.
externalizeDeps({
except: [
'@some/obscure/dependency',
/^@some\/obscure(?:\/.+)?$/,
],
})