-
-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] ESM import syntax support #10615
Comments
Shouldn't the order of arguments follow JS here? Also, I hate JS. |
FWIW here's a macro based implementation: https://github.com/back2dos/jsImport#jsimport---use-es6-imports-in-haxe Never actually used it in production, so I can't vouch for it, but I think it highlights the three different cases rather well (as for the corresponding Haxe syntax, I'll leave you to judge its suitability). |
@back2dos thanks for the link! Can confirm it works well, I had to add a variant where you specify the exportName: back2dos/jsImport#1 but otherwise it's perfect @sonygod: try this: haxelib git jsImport https://github.com/haxiomic/jsImport Add it to your build arguments --library jsImport And replace @:jsRequire with @:js.import, for orbit controls: @:js.import("three/examples/jsm/controls/OrbitControls.js", "OrbitControls") extern class OrbitControls { Notice we've also added |
If everyone agrees that the jsImport approach is good, I can port that to the compiler. I don't think we have to reinvent any wheels here. |
@Simn is this planned for a Haxe 4 release? |
Haxe 4, no Haxe 5, who knows? 😅 |
I'd make a case for this to be bumped into a milestone. Almost everyone is on ESM modules in js world these days and those libraries currently can't be used from haxe (including the big ones like three.js for a few years) and I think implementation difficulty is relatively small compared to the impact |
JavaScript's native import syntax is gaining support and usage – the latest version of three.js no longer supports
require()
for some modules and so presently cannot be used with haxe haxiomic/dts2hx#110Haxe currently has
@:jsRequire
which when added to externs, generatesrequire()
calls for module importsI think we could add
@:jsImport
(or@:js.import
) which would generate import statements instead. For example:This would become
Or as Simn suggests, this may be better as
To mirror the js import syntax
The text was updated successfully, but these errors were encountered: