A Vite plugin that automatically excludes Node.js built-in modules and npm dependencies from the bundle.
npm install @praha/vite-plugin-externalTo use @praha/vite-plugin-external, import and add it to the plugins array in your Vite configuration file:
By default, this plugin will exclude:
- Node.js built-in modules
- Dependencies listed in package.json
import { externalPlugin } from '@praha/vite-plugin-external';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
externalPlugin(),
],
});You can customize the behavior of the plugin by passing an options object:
import { externalPlugin } from '@praha/vite-plugin-external';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
externalPlugin({
packageJsonPath: './path/to/package.json', // Specify a custom package.json path
include: ['some-package', /^@scoped\/.*$/], // Explicitly externalize specific packages
exclude: ['some-lib'], // Do not externalize certain packages
}),
],
});| Name | Type | Description |
|---|---|---|
packageJsonPath |
string |
Path to a custom package.json file. Defaults to the project's root package.json. |
include |
string | RegExp | Array<string | RegExp> |
Packages to always externalize. |
exclude |
string | RegExp | Array<string | RegExp> |
Packages to explicitly prevent from being externalized. |
Contributions, issues and feature requests are welcome.
Feel free to check issues page if you want to contribute.
Copyright © PrAha, Inc.
This project is MIT licensed.