diff options
Diffstat (limited to 'sw-ui-kt')
-rw-r--r-- | sw-ui-kt/build.gradle.kts | 73 | ||||
-rw-r--r-- | sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/SevenWondersUi.kt | 23 | ||||
-rw-r--r-- | sw-ui-kt/src/main/web/index.html | 3 |
3 files changed, 98 insertions, 1 deletions
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<Copy>("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 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> - <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> + <link rel="shortcut icon" href="${publicPath}favicon.ico"> <!-- Notice the use of %PUBLIC_URL% in the tag above. It will be replaced with the URL of the `public` folder during the build. @@ -27,5 +27,6 @@ To begin the development, run `npm start`. To create a production bundle, use `npm run build`. --> + <script src="${bundle}"></script> </body> </html> |