Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda