Hey I just tried to create a js module in an exist...
# javascript
m
Hey I just tried to create a js module in an existing kotlin multiplatform project and I can’t get it working. I don’t have any experience with js so it makes things harder. I created a new module in the project and performed the steps described in gradle setup section in the documentation. I would like to make it work without any unnecessary libraries, just the simplest setup where I have a html file and some kotlin code that I can run in the browser. I looked for sample apps on github but I found only some old ones or some more complex solutions that use react or other libs. Is there some sort of a doc/blog post/sample that I could take look at?
i
Hello, unfortunately documentation is in progress now For basic usage of Kotlin/JS in multiplatform you need to declare js target like
Copy code
js {
browser()
}
and declare js stdlib dependency
Copy code
sourceSets {
     main {
           dependencies {
               implementation(kotlin("stdlib-js"))
           }
    }
}
Now you can create source code in
jsMain
module using Kotlin
m
Yeah I have that in
common
module, but I would like to create a separate module for the webpage and add
common
module as a dependency. Currently my setup looks like this: I have a
common
module with targets:
jvm
android
ios
and
js
each target is configured properly. I have a separate module for
android
ios
and
jvm
and each of those includes
common
as a dependency. Now I’m trying to add separate module for js app that will include
common
as a dependency.
I tried to create a js project with intellij and see how it’s configured but the project setup UI allows to create only idea project, not a gradle one
I wish there would be a doc describing how to create a simple kotlin js
hello world
project from scratch and showing how to run it in browser.
i
When you create new submodule, you can select Gradle point, and then select Kotlin/JS for browser
m
I missed that option somehow! Thank you, seems like what I’m looking for 🙂
I checked only under
Kotlin
on the left 🤦‍♂️