Skip to content

A Vite plugin that automatically excludes Node.js built-in modules and npm dependencies from the bundle.

License

Notifications You must be signed in to change notification settings

praha-inc/vite-plugin-external

Repository files navigation

@praha/vite-plugin-external

npm version npm download license Github

A Vite plugin that automatically excludes Node.js built-in modules and npm dependencies from the bundle.

👏 Getting Started

Installation

npm install @praha/vite-plugin-external

Usage

To use @praha/vite-plugin-external, import and add it to the plugins array in your Vite configuration file:

Basic Usage

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(),
  ],
});

With Options

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
    }),
  ],
});

Options

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.

🤝 Contributing

Contributions, issues and feature requests are welcome.

Feel free to check issues page if you want to contribute.

📝 License

Copyright © PrAha, Inc.

This project is MIT licensed.

About

A Vite plugin that automatically excludes Node.js built-in modules and npm dependencies from the bundle.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors