Browse Source

resources demo js workaround

dima-avdeev/resources-demo-js-workaround
dima.avdeev 1 year ago
parent
commit
0af19270f2
  1. 2
      components/README.md
  2. 36
      components/resources/demo/jsApp/build.gradle.kts
  3. 15
      components/resources/demo/jsApp/src/jsMain/kotlin/main.js.kt
  4. BIN
      components/resources/demo/jsApp/src/jsMain/resources/dir/img.png
  5. BIN
      components/resources/demo/jsApp/src/jsMain/resources/img.webp
  6. 10
      components/resources/demo/jsApp/src/jsMain/resources/index.html
  7. 0
      components/resources/demo/jsApp/src/jsMain/resources/styles.css
  8. 1
      components/resources/demo/shared/build.gradle.kts
  9. 10
      components/resources/demo/shared/src/jsMain/kotlin/main.js.kt
  10. 1
      components/settings.gradle.kts

2
components/README.md

@ -11,7 +11,7 @@ in Android Studio or in AppCode with [installed CocoaPods](https://kotlinlang.or
`./gradlew :resources:demo:desktopApp:run`
### Run JS in browser with WebAssembly Skia via Gradle:
`./gradlew :resources:demo:shared:jsBrowserDevelopmentRun`
`./gradlew :resources:demo:jsApp:jsBrowserDevelopmentRun`
### Run MacOS via Gradle:
- on Intel CPU: `./gradlew :resources:demo:shared:runDebugExecutableMacosX64`

36
components/resources/demo/jsApp/build.gradle.kts

@ -0,0 +1,36 @@
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}
val copyResources = tasks.create("copyJsResourcesWorkaround", Copy::class.java) {
from(project(":resources:demo:shared").file("src/commonMain/resources"))
to("build/processedResources/js/main")
}
kotlin {
js(IR) {
browser {
this.commonWebpackConfig {
println("this.outputPath: ${this.outputPath}")
this.devServer?.contentBase
}
this.webpackTask {
this.dependsOn(copyResources)
}
}
binaries.executable()
}
sourceSets {
val jsMain by getting {
dependencies {
implementation(project(":resources:demo:shared"))
}
resources.srcDirs += project(":resources:demo:shared").file("src/commonMain/resources")
}
}
}
compose.experimental {
web.application {}
}

15
components/resources/demo/jsApp/src/jsMain/kotlin/main.js.kt

@ -0,0 +1,15 @@
/*
* Copyright 2020-2023 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
import androidx.compose.ui.window.Window
import org.jetbrains.skiko.wasm.onWasmReady
fun main() {
onWasmReady {
Window("Resources demo") {
MainView()
}
}
}

BIN
components/resources/demo/jsApp/src/jsMain/resources/dir/img.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
components/resources/demo/jsApp/src/jsMain/resources/img.webp

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

10
components/resources/demo/shared/src/jsMain/resources/index.html → components/resources/demo/jsApp/src/jsMain/resources/index.html

@ -7,10 +7,10 @@
<link type="text/css" rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>compose multiplatform web demo</h1>
<div>
<canvas id="ComposeTarget" width="800" height="600"></canvas>
</div>
<script src="shared.js"> </script>
<h1>compose multiplatform web demo</h1>
<div>
<canvas id="ComposeTarget" width="800" height="600"></canvas>
</div>
<script src="jsApp.js"> </script>
</body>
</html>

0
components/resources/demo/shared/src/jsMain/resources/styles.css → components/resources/demo/jsApp/src/jsMain/resources/styles.css

1
components/resources/demo/shared/build.gradle.kts

@ -14,7 +14,6 @@ kotlin {
iosSimulatorArm64()
js(IR) {
browser()
binaries.executable()
}
macosX64 {
binaries {

10
components/resources/demo/shared/src/jsMain/kotlin/main.js.kt

@ -1,5 +1,5 @@
/*
* Copyright 2020-2022 JetBrains s.r.o. and respective authors and developers.
* Copyright 2020-2023 JetBrains s.r.o. and respective authors and developers.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
@ -14,14 +14,6 @@ import androidx.compose.ui.window.Window
import org.jetbrains.compose.resources.demo.shared.UseResources
import org.jetbrains.skiko.wasm.onWasmReady
fun main() {
onWasmReady {
Window("Resources demo") {
MainView()
}
}
}
@Composable
fun MainView() {
Column(modifier = Modifier.fillMaxSize()) {

1
components/settings.gradle.kts

@ -22,4 +22,5 @@ include("AnimatedImage:demo")
include(":resources:library")
include(":resources:demo:androidApp")
include(":resources:demo:desktopApp")
include(":resources:demo:jsApp")
include(":resources:demo:shared")

Loading…
Cancel
Save