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

257
Visualizações
Terser: prefix all mangled variables and functions

I'm working on a single-file script that is meant to be included on pages through a <script> tag, it's being built with Vite.js using the Terser minifier.

After making changes I noticed that the built version of my script was suddenly throwing errors whenever I called Google Analytics code.

After doing some digging, I noticed one of the other packages on a site I was including the script on was calling a function called ga(). The error is happening because Terser is minifying/mangling a function in my script and naming it ga(), which then conflicts with this other function I have no control over.

I assumed Terser would have an option to either

  • not mangle to a specific name
  • prefix all mangled functions

But it doesn't seem to have either.

I've managed to fix the problem by adding the following to my config:

    minify: "terser",
    terserOptions: {
      keep_fnames: true,
    },

Which stops Terser from mangling ANY function names, but obviously this isn't great as it's wasting a ton of potential for minification.

Is there any way to tell Terser to still mangle all functions, but to do so while also prefixing it with a_ for example?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Yes you can do it with regex, You can check this post or go to mangle.properties for complete documentation.

terserOptions: {
    mangle: {
        properties: {
            regex: /(^P1|^p1|^_p1)[A-Z]\w*/
        }
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
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