Need help exposing classes to JS then bundling with esbuild

I’m building a Three.js application using the dts2hx example from @haxiomic. I can expose the Main class like so:
@:expose("MyClass") class Main { …

This compiles to main.js and is available in browser as the MyClass object, e.g. new MyClass(); However the esbuild bundles it with some other libraries (as bundle.js) and then MyClass becomes unavailable in the browser when I load bundle.js instead of main.js. My suspicion is I need to configure esbuild properly. Has anyone solved this issue in their own projects?

It depends a bit on what you mean by “available in browser”, but I would assume you want to have it defined globally (i.e. on the window object).

The easiest way to do that is to find a good place to put untyped window.MyClass = Main;. In the entry point class, the main method will do, otherwise you can do this:

class Whatever {
  static function __init__() {
    untyped window.SomeName = Whatever;

Be careful about DCE though. A full example is here: Try Haxe!

Works perfect Juraj, thanks!