Skip to content

Commit 276c933

Browse files
authored
Merge pull request #382 from kkalisz/feature/molecule_wasm
added support for molecule for js wasm
2 parents 26b46ac + ed6dc0d commit 276c933

File tree

6 files changed

+63
-0
lines changed

6 files changed

+63
-0
lines changed

precompose-molecule/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
12
import java.util.Properties
23

34
plugins {
@@ -31,6 +32,10 @@ kotlin {
3132
js(IR) {
3233
browser()
3334
}
35+
@OptIn(ExperimentalWasmDsl::class)
36+
wasmJs {
37+
browser()
38+
}
3439
sourceSets {
3540
val commonMain by getting {
3641
dependencies {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package moe.tlaster.precompose.molecule
2+
3+
import kotlinx.coroutines.Dispatchers
4+
import kotlin.coroutines.CoroutineContext
5+
6+
internal actual fun providePlatformDispatcher(): CoroutineContext = Dispatchers.Main

sample/molecule/build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
22
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
3+
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
4+
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
35

46
plugins {
57
kotlin("multiplatform")
@@ -37,6 +39,25 @@ kotlin {
3739
}
3840
}
3941
jvm()
42+
@OptIn(ExperimentalWasmDsl::class)
43+
wasmJs {
44+
moduleName = "composeApp"
45+
browser {
46+
val projectDirPath = project.projectDir.path
47+
commonWebpackConfig {
48+
outputFileName = "composeApp.js"
49+
devServer =
50+
(devServer ?: KotlinWebpackConfig.DevServer()).apply {
51+
static =
52+
(static ?: mutableListOf()).apply {
53+
// Serve sources to debug inside browser
54+
add(projectDirPath)
55+
}
56+
}
57+
}
58+
}
59+
binaries.executable()
60+
}
4061

4162
sourceSets {
4263
val commonMain by getting {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package moe.tlaster.precompose.molecule.sample
2+
3+
import androidx.compose.ui.ExperimentalComposeUiApi
4+
import androidx.compose.ui.window.ComposeViewport
5+
import kotlinx.browser.document
6+
7+
@OptIn(ExperimentalComposeUiApi::class)
8+
fun main() {
9+
ComposeViewport(document.body!!) {
10+
App()
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>molecule</title>
7+
<link type="text/css" rel="stylesheet" href="styles.css">
8+
<script type="application/javascript" src="composeApp.js"></script>
9+
</head>
10+
<body>
11+
</body>
12+
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
html, body {
2+
width: 100%;
3+
height: 100%;
4+
margin: 0;
5+
padding: 0;
6+
overflow: hidden;
7+
}

0 commit comments

Comments
 (0)