Skip to content

Add wasm with compose final #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: final
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c1e5dea
Add solution including MongoDB
SebastianAigner Apr 16, 2020
566b657
Group ShoppingListItem routes by path
SebastianAigner Apr 16, 2020
00286de
Fix https://github.com/kotlin-hands-on/hands-on/issues/82
SebastianAigner Jun 29, 2020
b27964a
kotlin.browser => kotlinx.browser
SebastianAigner Aug 26, 2020
f8d5666
Update useEffect to use new, consistent API
SebastianAigner Jul 2, 2021
ef6c599
Update for wrappers pre.265
SebastianAigner Nov 11, 2021
299cc97
Change capitalization of "App"
SebastianAigner Nov 11, 2021
4ecbd06
Change capitalization of "InputComponent"
SebastianAigner Nov 11, 2021
db7eeaf
Use delegation
SebastianAigner Nov 11, 2021
3283b7f
Update to new Kotlin-React DSL
SebastianAigner Feb 15, 2022
fce5c5a
Adjust for Ktor 2.x APIs
SebastianAigner Aug 10, 2022
b4bebe1
Remove unnecessary window.location.origin usage.
NightlyNexus Oct 2, 2022
8aba666
Update Server.kt
pristalovpavel Mar 27, 2023
f96177b
update: js ir and version upgrade
danil-pavlov Jun 17, 2023
6fcd4c1
Gradle: use Configuration avoidance
CristianGM May 2, 2022
c28fdcc
Bumpt version to 1.9.10 with the relevant changes
JSMonk Aug 30, 2023
6b9788e
remove unused import
JSMonk Aug 30, 2023
874ac28
Remove unnecessary `get` handler
JSMonk Sep 4, 2023
e4c122e
Add basic UI for the compose app with Wasm
JSMonk Jan 5, 2024
e63afab
Add API emulation
JSMonk Jan 5, 2024
d61ee81
Add KTO
JSMonk Jan 5, 2024
27641ba
Use syntax sugar the state
JSMonk Jan 5, 2024
ce02939
Add gradle property to switch in between JS and WASM
JSMonk Jan 5, 2024
5cc51be
Uncomment server logic for MongoDB
JSMonk Jan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions AddShoppingListElement.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
POST http://localhost:9090/shoppingList
Content-Type: application/json

{
"desc": "Peppers 🌶",
"priority": 5
}
1 change: 1 addition & 0 deletions DeleteShoppingListElement.http
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE http://localhost:9090/shoppingList/AN_ID_GOES_HERE
68 changes: 47 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack

val kotlinVersion = "1.7.20-Beta"
val serializationVersion = "1.3.3"
val ktorVersion = "2.0.3"
val serializationVersion = "1.6.2"
val ktorVersion = "3.0.0-wasm2"
val logbackVersion = "1.2.11"
val kotlinWrappersVersion = "1.0.0-pre.354"
val kotlinWrappersVersion = "1.0.0-pre.621"
val kmongoVersion = "4.5.0"

plugins {
kotlin("multiplatform") version "1.7.20-Beta"
kotlin("multiplatform") version "1.9.21"
application //to run JVM part
kotlin("plugin.serialization") version "1.7.20-Beta"
kotlin("plugin.serialization") version "1.9.21"
id("org.jetbrains.compose") version "1.6.0-alpha01"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
maven("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
}

kotlin {
Expand All @@ -29,11 +31,19 @@ kotlin {
binaries.executable()
}
}
wasmJs {
browser {
binaries.executable()
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
implementation(compose.runtime)
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
}
}

Expand Down Expand Up @@ -61,36 +71,52 @@ kotlin {
val jsMain by getting {
dependencies {
implementation("io.ktor:ktor-client-js:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation(project.dependencies.enforcedPlatform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:$kotlinWrappersVersion"))
implementation("org.jetbrains.kotlin-wrappers:kotlin-react")
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
}
}

val wasmJsMain by getting {
dependencies {
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material3)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0-RC2")
}
}
}
}

application {
mainClass.set("ServerKt")
}

compose.experimental {
web.application {}
}

// include JS artifacts in any JAR we generate
tasks.getByName<Jar>("jvmJar") {
tasks.named<Jar>("jvmJar").configure {
val taskPrefix = if (project.properties.get("app.run.wasm") == "true") "wasmJs" else "js"
val taskName = if (project.hasProperty("isProduction")
|| project.gradle.startParameter.taskNames.contains("installDist")
) {
"jsBrowserProductionWebpack"
"${taskPrefix}BrowserProductionWebpack"
} else {
"jsBrowserDevelopmentWebpack"
"${taskPrefix}BrowserDevelopmentWebpack"
}
val webpackTask = tasks.getByName<KotlinWebpack>(taskName)
dependsOn(webpackTask) // make sure JS gets compiled first
from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)) // bring output file along into the JAR
val webpackTask = tasks.named<KotlinWebpack>(taskName)
dependsOn(webpackTask)
from(webpackTask.map { it.outputDirectory }) // bring output file along into the JAR
into("static")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "1.8"
}
Expand All @@ -109,10 +135,10 @@ distributions {
}

// Alias "installDist" as "stage" (for cloud providers)
tasks.create("stage") {
dependsOn(tasks.getByName("installDist"))
tasks.register("stage") {
dependsOn(tasks.named("installDist"))
}

tasks.getByName<JavaExec>("run") {
classpath(tasks.getByName<Jar>("jvmJar")) // so that the JS artifacts generated by `jvmJar` can be found and served
}
tasks.named<JavaExec>("run").configure {
classpath(tasks.named<Jar>("jvmJar")) // so that the JS artifacts generated by `jvmJar` can be found and served
}
10 changes: 9 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
kotlin.code.style=official
kotlin.code.style=official
kotlin.js.compiler=ir
kotlin.incremental=true
kotlin.incremental.js=true
kotlin.incremental.js.ir=true
kotlin.incremental.js.klib=true
org.jetbrains.compose.experimental.wasm.enabled=true
kotlin.daemon.jvmargs=-Xmx4G
app.run.wasm=false
Loading