New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

vite-plugin-externalize-dependencies

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-externalize-dependencies

A simplified plugin for Vite that allows you to exclude specific dependencies from the Vite bundle during development.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
6K
-24.82%
Maintainers
1
Weekly downloads
 
Created
Source

Vite Plugin Externalize Dependencies npm

A simplified plugin for Vite that allows you to exclude specific dependencies from the Vite bundle during development.

The following errors/warnings are supressed:

  • The entry point [moduleName] cannot be marked as external
  • Do not know how to load path: [namespace:moduleName]
  • Failed to resolve import [dependency] from [sourceFile]. Does the file exist?
  • The following dependencies are imported but could not be resolved: [dependency] (imported by [sourceFile])

Table of Contents

Installation

To install the plugin, use npm:

npm i vite-plugin-externalize-dependencies --save-dev

Usage

After installing the plugin, import it, and add it to Vite configuration:

import { defineConfig } from "vite";
import externalize from "vite-plugin-externalize-dependencies";

export default defineConfig({
  plugins: [
    externalize({
      externals: [
        "react", // Externalize "react", and all of its subexports (react/*), such as react/jsx-runtime
        /^external-.*/, // Externalize all modules starting with "external-"
        (moduleName) => moduleName.includes("external"), // Externalize all modules containing "external",
      ],
    }),
  ],
});

Modules can be externalized by name (exact match), by regex, or by a custom function (returning true to externalize the module). The plugin will automatically externalize all subexports of a module, such as react/jsx-runtime.

Requirements

The plugin is intended to be consumed by Vite.

Contributing and Development

Contributions are welcome! If you wish to contribute, you can use the following npm commands to help facilitate your development process:

  • dev: Serve index.html for development testing.
  • build: Build the plugin.
  • test: Run tests to verify expected outputs.

Use them as follows:

npm run dev
npm run build
npm run test

Please feel free to open a pull request with your changes or improvements.

Known Issues & limitations

This plugin is designed to work during development. For production, users should manually configure build.rollupOptions.external in Vite.

Support

If you encounter any problems or have any issues, please open a new issue in the GitHub repository.

License

This project is licensed under the MIT License.

Keywords

vite

FAQs

Package last updated on 24 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts