From 362c1060bd99186a1d372fa89a6b7a470f387d34 Mon Sep 17 00:00:00 2001 From: jbion Date: Thu, 23 May 2019 18:06:48 +0200 Subject: Attempt at Kotlin frontend plugin --- sw-ui-kt/build.gradle.kts | 73 ++++++++++++++++++++++ .../org/luxons/sevenwonders/ui/SevenWondersUi.kt | 23 +++++++ sw-ui-kt/src/main/web/index.html | 3 +- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 sw-ui-kt/build.gradle.kts create mode 100644 sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/SevenWondersUi.kt (limited to 'sw-ui-kt') diff --git a/sw-ui-kt/build.gradle.kts b/sw-ui-kt/build.gradle.kts new file mode 100644 index 00000000..5c84a917 --- /dev/null +++ b/sw-ui-kt/build.gradle.kts @@ -0,0 +1,73 @@ +import org.jetbrains.kotlin.gradle.frontend.util.frontendExtension +import org.jetbrains.kotlin.gradle.frontend.webpack.WebPackExtension +import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile + +plugins { + id("kotlin2js") + id("org.jetbrains.kotlin.frontend") //version "0.0.45" +} + +repositories { + jcenter() + maven(url = "https://kotlin.bintray.com/kotlin-js-wrappers") +} + +dependencies { + implementation(kotlin("stdlib-js")) + implementation(project(":sw-common-model")) + + implementation("org.jetbrains:kotlin-react-dom:16.6.0-pre.67-kotlin-1.3.11") +} + +val staticFilesBuildDir = "${project.buildDir.path}/static" +val staticFilesSrcDir = "$projectDir/src/main/web" + +tasks { + "compileKotlin2Js"(Kotlin2JsCompile::class) { + kotlinOptions.metaInfo = true + kotlinOptions.outputFile = "${project.buildDir.path}/js/${project.name}.js" + kotlinOptions.sourceMap = true + kotlinOptions.moduleKind = "commonjs" + kotlinOptions.main = "call" + } + + register("copyStatic") { + dependsOn("bundle") + from("${project.buildDir.path}/bundle", staticFilesSrcDir) + into(staticFilesBuildDir) + + val webpack = project.frontendExtension.bundles().first { it is WebPackExtension } as WebPackExtension + val bundleName = webpack.bundleName + val publicPath = webpack.publicPath + filesMatching("*.html") { + expand("bundle" to "$bundleName.bundle.js", "publicPath" to publicPath) + } + } + + build { + dependsOn("copyStatic") + } +} + +kotlinFrontend { + + sourceMaps = true + + webpack { + bundleName = "seven-wonders-ui" + contentPath = file(staticFilesBuildDir) + } + + npm { +// dependency("@blueprintjs/core", "3.15.1") + dependency("react", "16.8.3") + dependency("react-dom", "16.8.3") + dependency("react-redux", "5.0.7") + } +} + +fun org.jetbrains.kotlin.gradle.frontend.KotlinFrontendExtension.webpack( + configure: org.jetbrains.kotlin.gradle.frontend.webpack.WebPackExtension.() -> Unit +) { + bundle("webpack", delegateClosureOf(configure)) +} diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/SevenWondersUi.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/SevenWondersUi.kt new file mode 100644 index 00000000..5d9d9be6 --- /dev/null +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/SevenWondersUi.kt @@ -0,0 +1,23 @@ +package org.luxons.sevenwonders.ui + +import react.RBuilder +import react.dom.* +import kotlin.browser.document +import kotlin.browser.window + +fun main() { + window.onload = { + render(document.getElementById("root")!!) { + app() + } + } +} + +fun RBuilder.app() = div { + h1 { + +"Seven Wonders" + } + p { + +"Great app!" + } +} diff --git a/sw-ui-kt/src/main/web/index.html b/sw-ui-kt/src/main/web/index.html index 32b449cb..74cac462 100644 --- a/sw-ui-kt/src/main/web/index.html +++ b/sw-ui-kt/src/main/web/index.html @@ -3,7 +3,7 @@ - + + -- cgit