Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

256
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!