1. esbuild-plugin-globals
esbuild plugin that provides Webpack's externals functionality.
esbuild-plugin-globals
Package: esbuild-plugin-globals
Created by: a-b-r-o-w-n
Last modified: Mon, 06 Mar 2023 17:17:42 GMT
Version: 0.2.0
License: MIT
Downloads: 7,573
Repository: https://github.com/a-b-r-o-w-n/esbuild-plugin-globals

Install

npm install esbuild-plugin-globals
yarn add esbuild-plugin-globals

esbuild-plugin-globals

Provides Webpack's externals functionality for esbuild.

Install

npm:

 npm install --save-dev esbuild-plugin-globals

yarn:

 yarn add --dev esbuild-plugin-globals

Usage

 import esbuild from "esbuild";
import GlobalsPlugin from "esbuild-plugin-globals";

esbuild.build({
  entryPoints: ["src/index.ts"],
  bundle: true,
  plugins: [
    GlobalsPlugin({
      /**
       * Simple string pattern
       * Any module matching "react" will be replaced with
       * `module.exports = React`
       */
      react: "React",
      /**
       * Regular expression + resolver function
       * Invoked with matched module name and returns the module exports (or undefined).
       */
      "@some-scope/.*": (moduleName) => {
        /** strip the scope */
        const name = name.substring(12);
        /** generates module.exports = CamelCasedName */
        return camelCase(name);
      },
    }),
  ],
});

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code