Recently I published TeaVM preview (0.10.0-dev-8) which provides the ability to create JavaScript modules from Java code. This feature was requested by many TeaVM users for several years. Now it becomes possible without extra hacks.
Briefly, TeaVM comes with two new features: module type selection and exporting non-main methods. Since 0.9.0 TeaVM produces UMD wrappers instead of immediately-invoked function. Now it becomes possible to customize wrapper, and one of the is ES2015 module.
Another important thing is ability not only to import declarations from JavaScript (by means of implementing JSObject interface and using JSBody annotation), but to export Java declarations to JavaScript.
Note that this is only the very first implementation. I'm looking forward into implementing several improvements:
- Exporting constructors
- More compiler diagnostics (e.g. duplicate class export name)
- Generation of d.ts declarations
- Overriding methods by signature
and so on.
I'd be glad if you tested these features and provided feedback.
And please, don't forget that TeaVM needs your donates. If you like this project, or if these recent features are especially helpful for you use case and you want to thank me, become my sponsor, so I could have extra free capuccino (or perhaps even extra free Pho Bo) every month.