Skip to content

Commit 7efca7a

Browse files
committed
Add basic UI for the compose app with Wasm
1 parent 6fcd4c1 commit 7efca7a

File tree

9 files changed

+505
-571
lines changed

9 files changed

+505
-571
lines changed

build.gradle.kts

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
22

3-
val kotlinVersion = "1.8.21"
4-
val serializationVersion = "1.5.1"
3+
val serializationVersion = "1.6.2"
54
val ktorVersion = "2.3.0"
65
val logbackVersion = "1.2.11"
76
val kotlinWrappersVersion = "1.0.0-pre.561"
87
val kmongoVersion = "4.5.0"
98

109
plugins {
11-
kotlin("multiplatform") version "1.8.21"
10+
kotlin("multiplatform") version "1.9.21"
1211
application //to run JVM part
13-
kotlin("plugin.serialization") version "1.8.21"
12+
kotlin("plugin.serialization") version "1.9.21"
13+
id("org.jetbrains.compose") version "1.6.0-alpha01"
1414
}
1515

1616
group = "org.example"
1717
version = "1.0-SNAPSHOT"
1818

1919
repositories {
2020
mavenCentral()
21+
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
2122
}
2223

2324
kotlin {
@@ -29,11 +30,15 @@ kotlin {
2930
binaries.executable()
3031
}
3132
}
33+
wasmJs {
34+
browser {
35+
binaries.executable()
36+
}
37+
}
3238
sourceSets {
3339
val commonMain by getting {
3440
dependencies {
3541
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
36-
implementation("io.ktor:ktor-client-core:$ktorVersion")
3742
}
3843
}
3944

@@ -46,6 +51,7 @@ kotlin {
4651

4752
val jvmMain by getting {
4853
dependencies {
54+
implementation("io.ktor:ktor-client-core:$ktorVersion")
4955
implementation("io.ktor:ktor-serialization:$ktorVersion")
5056
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
5157
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
@@ -60,6 +66,7 @@ kotlin {
6066

6167
val jsMain by getting {
6268
dependencies {
69+
implementation("io.ktor:ktor-client-core:$ktorVersion")
6370
implementation("io.ktor:ktor-client-js:$ktorVersion")
6471
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
6572
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
@@ -68,13 +75,28 @@ kotlin {
6875
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
6976
}
7077
}
78+
79+
val wasmJsMain by getting {
80+
dependencies {
81+
implementation(compose.runtime)
82+
implementation(compose.ui)
83+
implementation(compose.foundation)
84+
implementation(compose.material3)
85+
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
86+
implementation(compose.components.resources)
87+
}
88+
}
7189
}
7290
}
7391

7492
application {
7593
mainClass.set("ServerKt")
7694
}
7795

96+
compose.experimental {
97+
web.application {}
98+
}
99+
78100
// include JS artifacts in any JAR we generate
79101
tasks.named<Jar>("jvmJar").configure {
80102
val taskName = if (project.hasProperty("isProduction")
@@ -85,7 +107,9 @@ tasks.named<Jar>("jvmJar").configure {
85107
"jsBrowserDevelopmentWebpack"
86108
}
87109
val webpackTask = tasks.named<KotlinWebpack>(taskName)
88-
from(webpackTask.map { File(it.destinationDirectory, it.outputFileName) }) // bring output file along into the JAR
110+
from(webpackTask.map { it.outputDirectory }) // bring output file along into the JAR
111+
into("static")
112+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
89113
}
90114

91115
tasks {
@@ -114,4 +138,4 @@ tasks.register("stage") {
114138

115139
tasks.named<JavaExec>("run").configure {
116140
classpath(tasks.named<Jar>("jvmJar")) // so that the JS artifacts generated by `jvmJar` can be found and served
117-
}
141+
}

gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
kotlin.code.style=official
2-
kotlin.js.compiler=ir
2+
kotlin.js.compiler=ir
3+
org.jetbrains.compose.experimental.wasm.enabled=true
4+
kotlin.daemon.jvmargs=-Xmx4G

0 commit comments

Comments
 (0)