https://kotlinlang.org logo
#javascript
Title
# javascript
r

Ryan Malaspina

11/03/2023, 6:02 PM
👋 Hello! I currently have a collection of typescript files that are getting compiled to javascript with npm, but each file still remains separate once it's in javascript. I'm looking to do the same with compiling Kotlin into javascript, but it looks like the IR compiler only supports outputting one js file for
whole-program
or
per-module
. Not all of these files need to stay as separate files, but there's enough I want to keep as separate files that making a module for each one would not be ideal. All of the files are pretty small but import an external typescript library which I can make external declarations for. The ones I want to keep as separate files each export a 'main' function with the same signature and each javascript file could get loaded and called dynamically by the external library. I did some experimenting with the command line compiler and got some basic Kotlin files compiled to javascript, but I'm not sure how to manage imports from other files and share the Kotlin js stdlib between them all
e

Edoardo Luppi

11/04/2023, 7:46 PM
per-file
is a valid granularity when targeting ES modules. However the per file support is still in early stage AFAIK, so you might encounter issues. Also, multiple
main
functions (e.g., one per file) are currently unsupported (I've seen a commit fixing this but not sure if it was backported).
r

Ryan Malaspina

11/07/2023, 5:33 PM
Thanks for the pointers! Can you link where you saw this?
2 Views