Robert Jaros
12/29/2023, 10:21 AM@JsModule
are included into the bundle? I've noticed when building wasmJs
target that the modules are generally included in alphabetical order. But it's not the case with js
target where the order seems to be random (but can be managed a bit if I disable 'useEsModules()` and use require()
calls instead of @JsModule
). I have two use cases where the order is significant. I need to include one js module first, before other modules. I also need to include one css
file last, after other modules. It's really problematic to achieve this in a shared wasmJS
+ JS
project. My "workaround" is to publish two NPM modules with names prefixed "aaa-" and "zzz-" which are then included as first and last. But I'm not sure if this solution will "survive" future upgrades 😉Svyatoslav Kuzmich [JB]
12/29/2023, 10:59 AMSet<String>
. It could change.
Proper useful stable ordering needs some additional design. It is obvious how to order multiple @JsModule
in the same .kt
file, but we would also need to come up with a spec for a cross-file and cross-module ordering. We currently don’t guarantee side-effects of module imports to be evaluated at all if imports from these modules are not used (even without DCE flag), and we’d probably need to specify this too.
Alternatively, we could bypass this design, and provide a way to run a custom ES module before the Kotlin module. Then you can import side-effects in the ordered way:
// before.mjs
import "first";
import "second";
// ...
import "css";
(edit: removed after.mjs)
Could you file an issue with your use cases?Svyatoslav Kuzmich [JB]
12/29/2023, 11:10 AMRobert Jaros
12/29/2023, 12:00 PM