diff --git a/precompose-molecule/build.gradle.kts b/precompose-molecule/build.gradle.kts index 48ca670a..cc7808ea 100644 --- a/precompose-molecule/build.gradle.kts +++ b/precompose-molecule/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl import java.util.Properties plugins { @@ -31,6 +32,10 @@ kotlin { js(IR) { browser() } + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + browser() + } sourceSets { val commonMain by getting { dependencies { diff --git a/precompose-molecule/src/wasmJsMain/kotlin/moe/tlaster/precompose/molecule/ProvidePlatformDispatcher.kt b/precompose-molecule/src/wasmJsMain/kotlin/moe/tlaster/precompose/molecule/ProvidePlatformDispatcher.kt new file mode 100644 index 00000000..31a18009 --- /dev/null +++ b/precompose-molecule/src/wasmJsMain/kotlin/moe/tlaster/precompose/molecule/ProvidePlatformDispatcher.kt @@ -0,0 +1,6 @@ +package moe.tlaster.precompose.molecule + +import kotlinx.coroutines.Dispatchers +import kotlin.coroutines.CoroutineContext + +internal actual fun providePlatformDispatcher(): CoroutineContext = Dispatchers.Main diff --git a/sample/molecule/build.gradle.kts b/sample/molecule/build.gradle.kts index bb26c7ae..9ef58c62 100644 --- a/sample/molecule/build.gradle.kts +++ b/sample/molecule/build.gradle.kts @@ -1,5 +1,7 @@ import org.jetbrains.compose.desktop.application.dsl.TargetFormat import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget +import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl +import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig plugins { kotlin("multiplatform") @@ -37,6 +39,25 @@ kotlin { } } jvm() + @OptIn(ExperimentalWasmDsl::class) + wasmJs { + moduleName = "composeApp" + browser { + val projectDirPath = project.projectDir.path + commonWebpackConfig { + outputFileName = "composeApp.js" + devServer = + (devServer ?: KotlinWebpackConfig.DevServer()).apply { + static = + (static ?: mutableListOf()).apply { + // Serve sources to debug inside browser + add(projectDirPath) + } + } + } + } + binaries.executable() + } sourceSets { val commonMain by getting { diff --git a/sample/molecule/src/wasmJsMain/kotlin/moe/tlaster/precompose/molecule/sample/Main.kt b/sample/molecule/src/wasmJsMain/kotlin/moe/tlaster/precompose/molecule/sample/Main.kt new file mode 100644 index 00000000..d0ea2c9e --- /dev/null +++ b/sample/molecule/src/wasmJsMain/kotlin/moe/tlaster/precompose/molecule/sample/Main.kt @@ -0,0 +1,12 @@ +package moe.tlaster.precompose.molecule.sample + +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.window.ComposeViewport +import kotlinx.browser.document + +@OptIn(ExperimentalComposeUiApi::class) +fun main() { + ComposeViewport(document.body!!) { + App() + } +} diff --git a/sample/molecule/src/wasmJsMain/resources/index.html b/sample/molecule/src/wasmJsMain/resources/index.html new file mode 100644 index 00000000..a8a4240c --- /dev/null +++ b/sample/molecule/src/wasmJsMain/resources/index.html @@ -0,0 +1,12 @@ + + +
+ + +