terser removes the function

168 views Asked by At

I am using terser to compress my code. But it turns out that it removes a function that is called only in html code (I understand that I set module: true)

I also set dead_code: false to keep unreachable code from being removed, but that didn't change anything at all, the function is still removed

What should I do?

Here are my options:

{
        compress: {
            drop_console: true,
            drop_debugger: false,
            dead_code: false,
        },
        mangle: {
            reserved: ["getUserStats"],
        },
        module: true,
        toplevel: true,
        keep_fnames: false
    }

Even when I call the function in another file that is also used in minification, the function is removed. What the hell???

1

There are 1 answers

0
deekep On

Ok, I did this and it worked:

function myFunc(){}

window.myFunc = myFunc;