esbuild-plugin-globals

v0.1.0
esbuild plugin that provides Webpack's externals functionality.
esbuild esbuild-plugin

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

Metadata

  • MIT
  • >=7
  • Andy Brown
  • released 2/5/2021

Downloads

Maintainers