'How to define global variable in Webpack?

I'm developing in an environment where the JS-engine doesn't have a global variable (e.g. window, global, globalThis, or this, etc.). Instead all the variables that are normally accessible through the global object, like window.Math, are accessible by just using Math.

So in order for Webpack to work I need to define my own implementation of the global variable. I tried googling around and couldn't find any answers for this use case. Webpack has a config for output.globalObject, but that that doesn't seem to work for this.

Webpack version: 5



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source