An esbuild plugin that replicates Webpack's externals functionality, allowing you to exclude certain modules from the bundle and replace them with global variables. Current stable version 0.2.0. It supports string patterns and RegExp with resolver functions for complex cases. Differs from native esbuild's 'external' by providing per-module global variable mapping, similar to Webpack's externals. Ships TypeScript declarations.
npm install esbuild-plugin-globalsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: mapping 'react', 'react-dom', and 'lodash' to global variables in an esbuild bundle.
Verify that the keys in the globals object match the import specifier exactly, e.g., 'react', not './react'.
Upgrade to 0.2.0 or later.
Ensure resolver functions return a string synchronously; async functions will not work.
Pass an object with at least one module mapping.
Either add the module to the globals object or ensure it's not external.
Ensure the value for a regex key is a function that accepts the module name and returns a string (or undefined).