esbuild icon indicating copy to clipboard operation
esbuild copied to clipboard

[Feature Request]: Provide a way to selectively keep class / function names

Open cernymatej opened this issue 1 year ago • 2 comments

The "keep names" option is sometimes necessary for certain use cases; however, it might significantly increase the bundle size in large projects, even if all one needs is to keep the names of a few classes. (my use case)

Would it be possible to add a way to specify a list of directories in which to keep the names? Or, perhaps even better, specify a regular expression for the name and/or add a special comment that would apply the rule to the class/function. I looked through the documentation and couldn't find such an option.

cernymatej avatar Feb 12 '24 13:02 cernymatej

You can do this by yourself:

class A {}
Object.defineProperty(A, "name", { value: "A", configurable: true })

hyrious avatar Feb 12 '24 14:02 hyrious

Interesting solution, but quite cumbersome and error-prone, in my opinion. Could something similar be implemented for classes extending a base class? Obviously, I can't use A.name in the expression 😕

cernymatej avatar Feb 12 '24 15:02 cernymatej