Skip to content

a-b-r-o-w-n/esbuild-plugin-globals

Repository files navigation

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

About

Provides Webpack's externals functionality for esbuild

Resources

License

Stars

Watchers

Forks

Packages

No packages published