godotjs / javascript

Javascript binding for godotengine
https://godotjs.github.io/
MIT License
980 stars 82 forks source link

Configuring esbuild for bundling classes issue #178

Closed joshbrew closed 1 month ago

joshbrew commented 1 year ago

I've been piecing together how to use this API from the main guide (the older examples won't load the jsx files) and I am having an issue bundling through esbuild which was used in some of the examples, albeit an older version. For whatever reason, esbuild recompiles the class syntax and then the ECMAscript interpreter can't recognize it. If I just reformat back then it works again, but this rules out bundling in my current config:

Before bundling:

281287424-833c3c45-7f1a-419d-b236-0447e1531b8f

After bundling:

281287335-a05b0f0f-c205-4f65-a3b1-69635cc984f5

So the top works, the bottom doesn't. What esbuild versions are you using or are there some special settings to use to prevent this? Otherwise it's just an esm compilation.

In the examples, the esbuild compilation still preseves the class x syntax instead of this odd var x = class { which anonymizes the class itself. This seems to be innate to esbuild.

nmerget commented 1 month ago

You can check this repo or this repo. Both work with the current editor with different esbuild settings.

nmerget commented 1 month ago

There is a new recommnded way for using TypeScript and GodotJS: https://godotjs.github.io/documentation/typescript/intro

godot-ts will bundle a working esbuild to generate your files and handle some edge-cases