Closed benmerckx closed 5 years ago
Looking into it, should generators that use RequireGenerator accept one (and the other generators) in their constructor so those can be defined in a custom config as well?
I don't quite get it, what is es module syntax and why?
Sorry, requiring stuff via import .. from ...
and export ...
, basically https://github.com/HaxeFoundation/haxe/issues/8033. Modules are currently the only way to do tree shaking for js. So releasing haxe generated js as a lib would benefit from this. Seems like it's already partly there in TSExternRequireGenerator, I'll look into it.
ES tree-shaking is irrelevant to Haxe JS output: tree-shaking only work with function exports - classes are always kept as-is so you'll have to rely on Haxe DCE. Additionally tree-shaking only works for modules without side effects which would have problems with Haxe static initialisation.
Aside from that hxgenjs produces JS files you should be able to use any way you like in JS.
ES tree-shaking is irrelevant to Haxe JS output:
It is. But if you were to release haxe generated js to be consumed via npm and bundlers you'd ideally want it generated as modules because it then enters the js ecosystem.
which would have problems with Haxe static initialisation
Right. It would impose quite a few restrictions on the generated code. Still I'm interested to see where it goes. Haxe currently functions as an endpoint and not a very good one at that (it doesn't have all the features of a js bundler and probably never will). So as I see it, it makes sense to optimize output to be consumed by existing js tooling.
hxgenjs outputs Haxe classes individually, and I believe without an entry point if desired. You must use a JS toolchain bundler unless you're running with Node.
I do. All I'm saying is clean js output (modules, split per file) is much preferable for existing js tools. Whether you'd like to use a bundler for your project or export generated js as an npm library (to be ultimately consumed by another bundler).
I think it may be useful to be more specific about what exactly you think should change in hxgenjs output 😅
Sorry, I realized this needed a different approach which was too big of a change to bring to hxgenjs, gave it a go here: https://github.com/benmerckx/genes
Did you look into supporting the es module syntax? Would haxe's static intialization make it hard or can it be attempted?