I have a library that sets some variables inside my module files.
const isBrowser =
typeof window !== 'undefined' && typeof window.document !== 'undefined';
export default class MyLib {
constructor() {
return isBorwser;
}
}
When babel-minify minifies the code, it becomes:
// minify test.js | prettier
const isBrowser =
"undefined" != typeof window && "undefined" != typeof window.document;
export default class MyLib {
constructor() {
return isBorwser;
}
}
As you can see, the isBrowser variable name is not mangled.
Can I tell babel-minify to mangle this variable name? It is defined inside a module, so it's not going to get exposed to the global scope, and even if, I would anyway like to mangle it because I know it's not going to be used by anyone else.
Thanks!
Replying to myself, I can pass { mangle: { topLevel: true }} to the babel-minify options.
The docs are here:
https://github.com/babel/minify/blob/master/packages/babel-preset-minify/README.md#options
Most helpful comment
Replying to myself, I can pass
{ mangle: { topLevel: true }}to the babel-minify options.The docs are here:
https://github.com/babel/minify/blob/master/packages/babel-preset-minify/README.md#options