Hacker News new | past | comments | ask | show | jobs | submit login

How's Kotlin compilation story to JavaScript? Can we do frontend in Kotlin?



Yes you can. I'm using the Fritz2 framework, which is pretty nice. There's another one called KVision. There are also some people doing react in Kotlin. You can also just program straight against the browser APIs as they have nice Kotlin DSLs for large parts of that.

Basically, to stay on topic, there are currently multiple kotlin compilers, including one that transpiles to Javascript. There is also tooling to interface with npms, to adapt typescript type mappings to Kotlin, and a few more goodies. Basically you lose the java standard library but you gain access to the browser APIs. Node API mappings are more of a work in progress but you should be able to target node.js as well. Browser side kotlin-js is pretty nice. You can do pretty much everything that you would normally do in js/ts. The build tooling uses gradle, which underneath uses webpack. There's a dead code eliminator, source maps, minification, etc.

Our web app uses cordova (for IOS and Android wrappers) with a few plugins, integrates Leaflet for maps, has reactive components (using co-routines and flows), has styled components, etc. So, pretty nice and modern way to do frontend. We have a handful of js things we integrate (like leaflet) and quite a few Kotlin multi platform things (like our own API client).

There is also a js backend for the new IR compiler, which is the thing that Jetbrains is currently building to unify the many Kotlin compilers they have. There is also a wasm compiler backend for that in the works but it's to early to rely on that probably. The IR to JVM backend is currently in beta and kotlin native also uses the IR compiler.

Kotlin-js is not for everyone just yet (a lot of these tools are beta quality) but if you are more comfortable with Kotlin than js/ts, it's worth checking out. That being said, our setup is quite nice compared to some react train wrecks I've been involved with.


How is the javascript interop? Can I use Angular/Vue and make kotlin components? Can I use any js/ts library from my kotlin code?


Pretty much yes to all of that. You can add npms as dependencies. Some typescript type annotations can be adapted to Kotlin type annotations. And if not, you can write your own. There's a dynamic keyword to deal with untyped javascript objects. Also you can define external interfaces for things. So, interop is pretty good and you have plenty of tools to integrate whatever. With Fritz2 you can create or integrate web components pretty easily as well.

That being said, it doesn't really make sense to try to use mainstream javascript frameworks as they are a poor fit for a strongly typed language like Kotlin. And in general, there aren't a lot of npms that are worth integrating. We made an exception for leaflet and that was pretty easy to integrate in the end. Otherwise we mostly use multiplatform kotlin libraries.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: