Registry / devops / esbuild-plugin-external-global

esbuild-plugin-external-global

JSON →
library1.0.1jsnpmunverified

An esbuild plugin that maps external modules to global variables, enabling bundle-size reduction by excluding dependencies like React, ReactDOM, or jQuery and referencing them via globals such as window.React. Version 1.0.1 is stable with minimal API surface. It provides a simple mapping object where keys are module names and values are global variable expressions. The plugin is commonly used in library builds where certain dependencies are provided by the host environment. It has TypeScript types and works with both CJS and ESM esbuild configurations. Compared to similar plugins like esbuild-plugin-externalize, this one focuses specifically on global variable fallbacks rather than file-based externals.

npm install esbuild-plugin-external-global
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-EXT
E
esbuild-plugin-external-global
devopsjavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

externalGlobalPlugin
import { externalGlobalPlugin } from 'esbuild-plugin-external-global'
const externalGlobalPlugin = require('esbuild-plugin-external-global')
Package exports a named export, not default. CJS require destructuring works but ESM import is recommended.
esbuild
import * as esbuild from 'esbuild'
const esbuild = require('esbuild')
esbuild is a peer dependency. Both CJS and ESM supported; use dynamic import for newer esbuild versions.
externalGlobalPlugin (type)
import type { ExternalGlobalPlugin } from 'esbuild-plugin-external-global'
TypeScript users can import the type for type-checking the plugin options.

Build a bundle excluding React and ReactDOM, expecting them as globals.

import * as esbuild from 'esbuild'; import { externalGlobalPlugin } from 'esbuild-plugin-external-global'; await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [ externalGlobalPlugin({ 'react': 'window.React', 'react-dom': 'window.ReactDOM' }) ] });
Debug
Known issues
breakingIn v1.0.0, the function name changed from 'externalGlobal' to 'externalGlobalPlugin'.
fix
Replace 'externalGlobal' with 'externalGlobalPlugin' in imports and usage.
affects: <1.0.0
gotchaThe plugin does not automatically set 'external' option; you must mark those packages as external in esbuild config.
fix
Add 'external: ["react", "react-dom"]' to esbuild options.
affects: >=0.0.0
gotchaGlobal variable expressions must evaluate to a function/object, not a string literal; incorrect quotes cause runtime errors.
fix
Use 'window.React' not '"window.React"'.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Build failed with 1 error: error: No matching export in "node_modules/esbuild-plugin-external-global/lib/index.js" for import "default"
Using default import instead of named import.
fix
Change 'import externalGlobalPlugin from...' to 'import { externalGlobalPlugin } from...'.
TypeError: Cannot read properties of undefined (reading 'onResolve')
Plugin not added to esbuild plugins array correctly.
fix
Ensure plugin is an object with setup function: wrap result of externalGlobalPlugin() in brackets: plugins: [externalGlobalPlugin({...})].
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-external-global — npm install esbuild-plugin-external-global · libregistry