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

258
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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