Skip to content

--keep-name scoping, consider a --format=aync-iife flag #4408

@edaanen

Description

@edaanen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions