My script will be executed by the Android app Tasker, which injects its own value for global that is a function that gets called like const val = global('%variableName').
I'm bundling this script with Webpack & Babel, and Babel generates this code:
t.g = (function () {
if ('object' == typeof globalThis) return globalThis
try {
return this || new Function('return this')()
} catch (t) {
if ('object' == typeof window) return window
}
})()
And then swaps out global(...) with t.g(...). I'd like to prevent this part of the transpilation altogether.
My babel config looks like:
module.exports = {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
"targets": {
"node": true
}
},
],
],
}
I added the preset-env configuration in an attempt to fix this, but no luck. I have also tried using ts-loader instead, but the results are the same. Hopefully I don't need to write my own babel plugin to post-process this in order to swap in some code like t.g = global.