I’ve been evaluating Kotlin/JS for usage in the Ne...
# javascript
a
I’ve been evaluating Kotlin/JS for usage in the Next.js project, and so far, it seems like an impossible task. Or maybe I’m not familiar with the tooling to bake it right (no experience with Kotlin yet). My current conclusion: Kotlin/JS does too many things that get in the way, like bundling and aggressive DCE. Is there an option to simply compile source files to JS, without bundling, with reasonable or no DCE, source files map 1-to-1 with compiled assets, all exports are preserved, etc. Some kind of library mode where the compiler doesn’t have an opinion on where the result will be used.
b
binaries.library + @JsExport
There's also #npm-publish to help it package it for easy consumption from js project
a
Thanks! Just tried it and it helps in preserving the exports in the output. I’ll continue digging.
I was able to use compiled assets in the Next.js app. Still, I don’t think it would scale well since the compiler generates one fat js file with all the exports being implemented via a weird wrapper that doesn’t seem statically optimizable/tree-shakable. And AFAICT Kotlin/JS doesn’t consider dynamic imports, which means the app would end up as a single fat js file.
b
Yep. Missing es6 support hurts it a lot for now
It's kinda ok for spa, but a dealbreaker for ssg/ssr
a
IMO Kotlin can learn a lot from ReScript regarding code generation and overall adoption strategy (in a tech context). I can see how painful it might be to incrementally introduce Kotlin/JS to an existing project.
m
It seems like the current tooling and examples oriented towards compiling the final end product in Kotlin, rather than creating assets that can be consumed in the JS side. The IR compiler seems to have some improvements in the pipeline (e.g generating .d.ts files), but at the moment, consuming Kotlin code from from Javascript is painful Some years ago we tried to consume Kotlin Multiplatform core logic from within an Angular or React application. It didn't go very well. Using the Kotlin/React wrappers has worked much better. Using functional components with the React wrapper and MUI is actually looking very promising. We can share the ViewModel, logic, etc. and using MUI in Kotlin/JS is very similar to Jetpack Compose.