https://kotlinlang.org logo
Title
g

Gunslingor

08/09/2020, 5:35 PM
BIG Question: What do yall do for front end frameworks with Ktor? I heard KotlinJS isn't really being developed or might be retired, I never really got it working with ktor. I don't get why ktor has CSS and HTML DSL inherent but not js. So what do people do for front end, just create JS files in the resources folder? For libraries that makes sense I guess but not custom frontend code, and I wouldn't mind moving away from JS. I mean if I write in JS why would someone write in kotlin HTML/CSS, module parts would end up isolated most likely. Trying to understand real world practical solutions, modern too... options. Assume I'm making a site like Wix, so I might use stuff like grapeJS and 3D junk.
Ruling out some options: 1. _*JS treated as static resources in ktor*_: keep coming back to this, but question testing and other stuff (like why my HTML and CSS is considered src but JS isn't, lol. 2. _*multiplatform w KotlinJS*_: doesn't play well with other plugins I found, trying to avoid it (I moved to gradle subprojects and I am happier, but even there I find many frameworks can't handle it, e.g. liferay). 3. _*React/angular/Equivalent + Ktor Gradle subprojects*: Good Example; What I was considering, maybe angularJS instead of React, I have more experience with it. A_lthough I'm not really sure what this buys you that using the ktor resources folder for housing JS wouldn't get you (thinking tooling and development speed). 4. 'Ktor Backend' + 'Ktor CSS/HTML & KotlinJS Frontend' as Gradle subprojects: not sure that's possible, if it were I should be able to combine backend and front end better. I think KotlinJS only plays well in an isolated multiplatform project or and isolated KotlinJS project.
r

Robert Jaros

08/09/2020, 6:07 PM
I've created some large fullstack apps with KVision and in my opinion Kotlin/JS works fine in MPP configuration if you have good configuration to workaround some nasty bugs. I'm using Spring backend but it should work fine with Ktor, too.
g

Gunslingor

08/09/2020, 6:09 PM
hmm.... Kvision; I forgot about this one, don't know much about it either. I'll dig into it a little. Would this be part of the same ktor project or could/should it be a gradle subproject?
r

Robert Jaros

08/09/2020, 6:10 PM
If you want to write your frontend code in Kotlin, you don't really have a lot options. You can use KVision, React-Kotlin from JB, probably also experiment with Fritz2 or Kweb.
If you don't want/need Kotlin, you can of course use anything you wish (Angular, Vue, Svelte, whatever you know best)
g

Gunslingor

08/09/2020, 6:12 PM
I'm not sure, maybe I should stick with classical JS/HTML/CSS... but even then I'm not sure how to go about the best way to develop and serve that up
r

Robert Jaros

08/09/2020, 6:12 PM
g

Gunslingor

08/09/2020, 6:14 PM
Yeah... I'm staying away from multiplatform plugin for sure. Bottom line: I have the strong impression I love gradle but hate gradle plugins, mostly because of my time with multiplatform and trying to make that work with other plugins... stuff is getting too opinionated, doesn't work with other stuff and many opinions seem illogical.
r

Robert Jaros

08/09/2020, 6:16 PM
I agree, It's hard to make MPP work with some other stuff. Last week I've spend whole two days to integrate MPP with Micronaut, because I haven't found any working example of MPP with Kapt and Kotlin Gradle DSL.
But with some effort it's possible ;-)
g

Gunslingor

08/09/2020, 6:17 PM
Gradle subprojects, honestly work better... but still, frameworks are opinionated and even that fails. So yeah... I think an opinionated ktor and isolated JS is what I'll do, angularJS. Still not sure the best way to serve that up with ktor.
r

Robert Jaros

08/09/2020, 6:17 PM
But sharing common Kotlin code between frontend and backend is worth this effort.
g

Gunslingor

08/09/2020, 6:18 PM
sure gradle subproject could handle it... common code = library IMHO
r

Robert Jaros

08/09/2020, 6:18 PM
MPP with gradle subprojects have other issues as well.
g

Gunslingor

08/09/2020, 6:18 PM
What am I doing wrong here, or what's the url to get it?
I think I can do all else if I get this, lol
r

Robert Jaros

08/09/2020, 6:22 PM
you want
/web/static/index.html
to work?
g

Gunslingor

08/09/2020, 6:22 PM
I wanna serve up my first html, js and css... index page...
yeah that route is fine
r

Robert Jaros

08/09/2020, 6:23 PM
have you tried
resources("web")
instead of
files("web")
?
I'm using this kind of configuration:
routing {
        static("/") {
            resources("assets")
            defaultResource("assets/index.html")
        }
    }
g

Gunslingor

08/09/2020, 6:25 PM
okay, this helps... starting to get some working statics. just a sec
Nice, I like this. I couldn't figure out how to set the default page... i.e. forward all random URLs to it, thought defaultResource would work but wrong.
static("/") {
    resources("web")
    defaultResource("web/index.html")
}
This does work for serving up my first file in a comprehendable way... will be curious to see what happens when I package this up in jars and wars using some other gradle plugin ,lol
r

Robert Jaros

08/09/2020, 6:29 PM
works fine when building fat jar with resources inside the package
but I haven't tried ktor with war packaging
g

Gunslingor

08/09/2020, 6:30 PM
Cool. So now I can just program in my resources folder with HTML/CSS/JS... still gotta figure out running tests on that stuff (HTML/JS/CSS), or maybe not. I can't seem to stop thinking like devOps engineer.
I guess jest is the solution there, so it really is all development in the browser... like the old days!
Thanks for the help, one word might have cost me 3 days 😃
Yeah... I did get a JS/JVM/Ktor multiplatofrm project working... but it took a month, had too many holes fixed with duck tape and super glue and was still partly broken (e.g. silly run warnings or wrrors, partly broken gradle tasks). I remember webpack was a nightmare, had to open a ticket and be given a workaround.
s

Sam

08/10/2020, 4:46 AM
`I heard KotlinJS isn't really being developed or might be retired`How did you hear about this?
g

Gunslingor

08/10/2020, 6:31 AM
Honestly I don't recall, may have been an obscure comment on a thread somewhere... I feel like I've read them all by now, lol, 8 years back
d

darkmoon_uk

08/10/2020, 7:30 AM
I've just had an extremely positive experience with Ktor + Kotlin/JS full-stack in recent days.
Not a web developer at all, but I was given a web task as a recruitment challenge and tackled it with this stack ...never used it before, worked admirably.
Was rapt when coroutines 'just worked' in transpiled JS and I could use Flows to process UI interactions.
I also haven't heard anything about Kotlin/JS being deprecated - calling FUD on this.
Though it does seem likely that Kotlin/JS will ultimately become just a stepping stone on the way to the new Kotlin/WASM support. Once this is eventually polished, it feels like there'd be little reason for /JS to exist.
g

Gunslingor

08/10/2020, 1:02 PM
I do see the potential of Kotlin, it's being developed in a way that could make it definitive... but it needs a lot of work. There should be more than one way to compile to multiplatform, I should be able to drop a function anywhere "Program(from="Kotlin", to="Pascal", compile=true, transpile=true) { } anywhere, with any language... that's multiplatform, lol. Plus Kotlin is still more wordy than python. I essentially have multiplatform working now, except I'm using gradle subprojects instead of the multiplatform plugin... I did get multiplatform working reasonably well, but as soon as I tried to walk outside the pardigm of the plugin while staying in the paradigm of gradle it broke.
Is this how you startyou KotlinJS programs? Seems to make sense, saw there where 4 things associated with the browser object, socument and window are 2. Trying to understand what a larger architecture would look like, if there are other considerations. Anyone got a good large KotlinJS example:
fun main() {
    document.addEventListener("DOMContentLoaded", {