Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
Prevent babel from transpiling `global` variable

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.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda