Babel plugin that transforms `globalThis` references to a ponyfill detecting the runtime environment (window, self, global, or fallback object). Version 1.0.0 released Jan 2021; single stable release with no further updates. Differentiates from @babel/plugin-transform-global-this by not relying on core-js and providing a lighter-weight transformation. Suitable for environments where globalThis is unsupported or for projects that prefer explicit polyfilling via Babel transpilation.
npm install babel-plugin-transform-globalthisVerified import paths — ran on the pinned version, not inferred.
Shows basic setup using .babelrc and transformation of globalThis to a runtime-detected global object.
Use @babel/plugin-transform-global-this or core-js for shared polyfill; or use module-level plugin to avoid duplication.
Ensure all cross-environment code uses globalThis explicitly; the plugin does not transform window, self, or global.
Accept the generated variable name; or fork the plugin to add configuration.
Use module.exports or .babelrc JSON format; e.g., module.exports = { plugins: ['babel-plugin-transform-globalthis'] };Ensure Babel is configured to run on the file where globalThis appears; add plugin to .babelrc or babel.config.json.