- Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I need the --keep-names flag because otherwise minified code in my UI framework would result in errors.
There might be calls like constructor.name and if the class was actually renamed this is an issue.
The --keep-names fixes this, but creates top level variables (dangerous scoping if not inside module).
Now you can wrap these inside an anonymous method with the --format=iife flag.
However, since most of the code these days contains async calls (await's) this wont work!
I would love to see an option --format=async-iife.
I now fixed these issues myself by wrapping some files (non-modules) after minifying into (async function()) blocks.
This way my async calls work and the global vars created by esbuild are scoped.
Otherwise I got errors (lazy loading of scripts) because esbuild will overwrite these globals in other loaded script files as part of the --keep-names flag.
So summary, for modules no issue, for entry files or oldschool .js files, it is.