├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── package-lock.json ├── package.json ├── settings.gradle ├── src ├── commonMain │ └── kotlin │ │ └── com │ │ └── starter │ │ └── common │ │ └── Sample.kt ├── commonTest │ └── kotlin │ │ └── sample │ │ └── SampleTests.kt ├── jsMain │ ├── kotlin │ │ └── com │ │ │ └── starter │ │ │ ├── common │ │ │ └── Sample.kt │ │ │ └── frontend │ │ │ ├── Main.kt │ │ │ └── component │ │ │ └── app │ │ │ ├── App.kt │ │ │ └── App.scss │ └── public │ │ ├── apple-icon.png │ │ ├── favicon.ico │ │ ├── index.html │ │ └── manifest.json ├── jsTest │ └── kotlin │ │ └── sample │ │ └── SampleTestsJS.kt ├── jvmMain │ └── kotlin │ │ └── com │ │ └── starter │ │ └── common │ │ └── Sample.kt └── jvmTest │ └── kotlin │ └── sample │ └── SampleTestsJVM.kt ├── webpack.common.js ├── webpack.dev.js └── webpack.prod.js /.gitignore: -------------------------------------------------------------------------------- 1 | /.gradle 2 | /.idea 3 | /build 4 | /node_modules 5 | 6 | *.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Graham Baldeck 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ## Intro 3 | 4 | This is a multiplatform project developed with the Kotlin 1.3.0-rc-146 Gradle plugin for IntelliJ, but you can use whatever IDE you would like since it comes with the gradle wrapper. Also, since this is build with the Kotlin 1.3 Release Candidate, it will only need minor updates once Kotlin 1.3 is released. I created this starter to help Kotlin developers with multiplatform Kotlin JS/JVM used with the Kotlin React wrapper and Webpack. 5 | 6 | It is setup with custom webpack configuration files (webpack.common.js, webpack.dev.js, webpack.prod.js) that I have commented for better understanding of what the config files do. I have also commented some of build.gradle. 7 | 8 | There is a working React component setup with the Kotlin React wrapper for you to build off of, and I have left the multiplatform sample files so that you can still see examples of how to do multiplatform development. 9 | 10 | I haven't added any frameworks for the JVM side of things, so that is open to whatever you would like to use. 11 | 12 | ## Kotlin/JS Module 13 | 14 | First, run: 15 | > npm install 16 | 17 | Then the Gradle task: 18 | > gradlew runDceJsKotlin 19 | 20 | Then for webpack dev-server do: 21 | > npm run serve 22 | 23 | Once it's running you can view it in the browser by going to `localhost:9000` 24 | 25 | For production build do: 26 | > npm run prod-build 27 | 28 | While the dev server is running you can run the `runDceJsKotlin` gradle task and it will automatically pick up the emitted Kotlin/JS files. 29 | 30 | The builds include JS source maps for the Kotlin/JS files as well. So you can setup a run configuration in IntelliJ to debug in the IDE or you can debug in your favorite browser's dev tools, whichever you prefer. 31 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'kotlin-multiplatform' version '1.3.0-rc-146' 3 | } 4 | apply plugin: 'kotlin-dce-js' //apply the dce plugin which gets rid of dead code in kotlin 5 | 6 | repositories { 7 | maven { url 'http://dl.bintray.com/kotlin/kotlinx.html' } 8 | maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' } 9 | maven { url 'http://dl.bintray.com/kotlin/kotlin-js-wrappers' } 10 | maven { url 'http://dl.bintray.com/kotlin/kotlinx' } 11 | mavenCentral() 12 | } 13 | 14 | 15 | 16 | kotlin { 17 | 18 | targets { 19 | fromPreset(presets.jvm, 'jvm') 20 | 21 | 22 | configure(fromPreset(presets.js, 'js')) { //needed to configure the JS target 23 | tasks.getByName(compilations.main.compileKotlinTaskName).kotlinOptions { 24 | sourceMap = true //create source maps for js files 25 | sourceMapEmbedSources = "always" //embed the kotlin files into the sourcemaps for viewing in the browser 26 | moduleKind = 'commonjs' //module type to be loaded by webpack 27 | } 28 | } 29 | } 30 | 31 | sourceSets { 32 | commonMain { 33 | dependencies { 34 | implementation 'org.jetbrains.kotlin:kotlin-stdlib-common' 35 | } 36 | } 37 | commonTest { 38 | dependencies { 39 | implementation 'org.jetbrains.kotlin:kotlin-test-common' 40 | implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common' 41 | } 42 | } 43 | jvmMain { 44 | dependencies { 45 | implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' 46 | } 47 | } 48 | jvmTest { 49 | dependencies { 50 | implementation 'org.jetbrains.kotlin:kotlin-test' 51 | implementation 'org.jetbrains.kotlin:kotlin-test-junit' 52 | } 53 | } 54 | jsMain { 55 | dependencies { 56 | implementation 'org.jetbrains.kotlin:kotlin-stdlib-js' 57 | implementation 'org.jetbrains:kotlin-react:16.5.2-pre.55-kotlin-1.2.71' 58 | implementation 'org.jetbrains:kotlin-react-dom:16.5.2-pre.55-kotlin-1.2.71' 59 | implementation 'org.jetbrains:kotlin-react-router-dom:4.3.1-pre.55-kotlin-1.2.71' 60 | } 61 | } 62 | jsTest { 63 | dependencies { 64 | implementation 'org.jetbrains.kotlin:kotlin-test-js' 65 | } 66 | } 67 | } 68 | 69 | 70 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbaldeck/react-js-jvm-kotlin-multiplatform/a10d4e2e004d55f588e3168cac95da2d8ac5039c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "starter", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "prod-build": "webpack --config webpack.prod.js", 8 | "serve": "webpack-dev-server --config webpack.dev.js" 9 | }, 10 | "author": "", 11 | "license": "MIT", 12 | "dependencies": { 13 | "core-js": "^2.5.7", 14 | "bootstrap": "^4.1.3", 15 | "perfect-scrollbar": "^1.4.0", 16 | "react": "^16.5.2", 17 | "react-dom": "^16.5.2", 18 | "react-router-dom": "^4.3.1", 19 | "reactstrap": "^6.5.0" 20 | }, 21 | "devDependencies": { 22 | "clean-webpack-plugin": "^0.1.19", 23 | "copy-webpack-plugin": "^4.5.2", 24 | "css-loader": "^1.0.0", 25 | "html-webpack-plugin": "^3.2.0", 26 | "node-sass": "^4.9.3", 27 | "sass-loader": "^7.1.0", 28 | "source-map-loader": "^0.2.4", 29 | "style-loader": "^0.23.0", 30 | "webpack": "^4.20.2", 31 | "webpack-cli": "^3.1.2", 32 | "webpack-dev-server": "^3.1.9", 33 | "webpack-merge": "^4.1.4", 34 | "write-file-webpack-plugin": "^4.4.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | resolutionStrategy { 3 | eachPlugin { 4 | if (requested.id.id == "kotlin-multiplatform") { 5 | useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}") 6 | } 7 | } 8 | } 9 | 10 | repositories { 11 | maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' } 12 | 13 | mavenCentral() 14 | 15 | maven { url 'https://plugins.gradle.org/m2/' } 16 | } 17 | } 18 | rootProject.name = 'starter' 19 | 20 | -------------------------------------------------------------------------------- /src/commonMain/kotlin/com/starter/common/Sample.kt: -------------------------------------------------------------------------------- 1 | package com.starter.common 2 | 3 | expect class Sample() { 4 | fun checkMe(): Int 5 | } 6 | 7 | expect object Platform { 8 | val name: String 9 | } 10 | 11 | fun hello(): String = "Hello from ${Platform.name}" 12 | 13 | fun samplePrint(): String = "Awesome sauce ${Sample().checkMe()}" -------------------------------------------------------------------------------- /src/commonTest/kotlin/sample/SampleTests.kt: -------------------------------------------------------------------------------- 1 | package sample 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | class SampleTests { 7 | @Test 8 | fun testMe() { 9 | assertTrue(Sample().checkMe() > 0) 10 | } 11 | } -------------------------------------------------------------------------------- /src/jsMain/kotlin/com/starter/common/Sample.kt: -------------------------------------------------------------------------------- 1 | package com.starter.common 2 | 3 | actual class Sample { 4 | actual fun checkMe() = 12 5 | } 6 | 7 | actual object Platform { 8 | actual val name: String = "JSLAND2" 9 | } -------------------------------------------------------------------------------- /src/jsMain/kotlin/com/starter/frontend/Main.kt: -------------------------------------------------------------------------------- 1 | package com.starter.frontend 2 | 3 | import com.starter.frontend.component.app.app 4 | import react.dom.render 5 | import kotlin.browser.document 6 | 7 | fun main(args: Array) { 8 | render(document.getElementById("root")) { 9 | app() 10 | } 11 | } -------------------------------------------------------------------------------- /src/jsMain/kotlin/com/starter/frontend/component/app/App.kt: -------------------------------------------------------------------------------- 1 | package com.starter.frontend.component.app 2 | 3 | import react.RBuilder 4 | import react.RComponent 5 | import react.RProps 6 | import react.RState 7 | import react.dom.div 8 | import kotlinext.js.require 9 | 10 | private class App: RComponent() { 11 | //the below init block tells webpack to load the SASS file as a module and uses the `Components` 12 | //alias we setup in webpack.common.js so we don't have to type out the whole path to the file 13 | init { require("Components/app/App.scss") } 14 | 15 | override fun RBuilder.render() { 16 | div(classes = "bm-app") { 17 | + "Hello Kotlin-React!!!" 18 | } 19 | } 20 | 21 | } 22 | 23 | fun RBuilder.app() = child(App::class) {} 24 | -------------------------------------------------------------------------------- /src/jsMain/kotlin/com/starter/frontend/component/app/App.scss: -------------------------------------------------------------------------------- 1 | .bm-app { 2 | color: blue; 3 | } -------------------------------------------------------------------------------- /src/jsMain/public/apple-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbaldeck/react-js-jvm-kotlin-multiplatform/a10d4e2e004d55f588e3168cac95da2d8ac5039c/src/jsMain/public/apple-icon.png -------------------------------------------------------------------------------- /src/jsMain/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbaldeck/react-js-jvm-kotlin-multiplatform/a10d4e2e004d55f588e3168cac95da2d8ac5039c/src/jsMain/public/favicon.ico -------------------------------------------------------------------------------- /src/jsMain/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%= htmlWebpackPlugin.options.title || 'Webpack App'%> 8 | 9 | 10 | 11 | 12 | 13 | <% for (var css in htmlWebpackPlugin.files.css) { %> 14 | 15 | <% } %> 16 | 17 | 18 | <% if (htmlWebpackPlugin.options.unsupportedBrowser) { %> 19 | 20 |
21 | Sorry, your browser is not supported. Please upgrade to 22 | the latest version or switch your browser to use this site. 23 | See outdatedbrowser.com 24 | for options. 25 |
26 | <% } %> 27 | 28 | <% if (htmlWebpackPlugin.options.appMountId) { %> 29 |
30 | <% } %> 31 | 32 | <% if (htmlWebpackPlugin.options.appMountIds && htmlWebpackPlugin.options.appMountIds.length > 0) { %> 33 | <% for (var index in htmlWebpackPlugin.options.appMountIds) { %> 34 |
35 | <% } %> 36 | <% } %> 37 | 38 | <% if (htmlWebpackPlugin.options.window) { %> 39 | 44 | <% } %> 45 | 46 | <% if (htmlWebpackPlugin.options.devServer) { %> 47 | 48 | <% } %> 49 | 50 | <% if (htmlWebpackPlugin.options.googleAnalytics) { %> 51 | 66 | <% } %> 67 | 68 | -------------------------------------------------------------------------------- /src/jsMain/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "starter", 3 | "name": "starter", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "192x192", 8 | "type": "image/png" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/jsTest/kotlin/sample/SampleTestsJS.kt: -------------------------------------------------------------------------------- 1 | package sample 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | class SampleTestsJS { 7 | @Test 8 | fun testHello() { 9 | assertTrue("JS" in hello()) 10 | } 11 | } -------------------------------------------------------------------------------- /src/jvmMain/kotlin/com/starter/common/Sample.kt: -------------------------------------------------------------------------------- 1 | package com.starter.common 2 | 3 | actual class Sample { 4 | actual fun checkMe() = 42 5 | } 6 | 7 | actual object Platform { 8 | actual val name: String = "JVM" 9 | } -------------------------------------------------------------------------------- /src/jvmTest/kotlin/sample/SampleTestsJVM.kt: -------------------------------------------------------------------------------- 1 | package sample 2 | 3 | import kotlin.test.Test 4 | import kotlin.test.assertTrue 5 | 6 | class SampleTestsJVM { 7 | @Test 8 | fun testHello() { 9 | assertTrue("JVM" in hello()) 10 | } 11 | } -------------------------------------------------------------------------------- /webpack.common.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 3 | 4 | module.exports = { 5 | entry: ["./build/kotlin-js-min/js/main/starter.js"], //The entry point to our app, all modules are loaded from here 6 | module: { 7 | // configuration regarding modules 8 | rules: [ 9 | { //this one loads the kotlin generated source maps for our kotlin emitted js files 10 | test: /\.js$/, 11 | include: [ 12 | path.resolve(__dirname, 'build/kotlin-js-min/js/main') 13 | ], 14 | use: ["source-map-loader"], 15 | enforce: "pre" 16 | }, 17 | { //this one passes any .scss files imported or "required" in our kotlin js application through these loaders 18 | "test": /\.scss$/, 19 | "use": [ 20 | "style-loader", 21 | "css-loader", 22 | "sass-loader" 23 | ] 24 | }, 25 | { //same as above but for css 26 | "test": /\.css$/, 27 | "use": [ 28 | "style-loader", 29 | "css-loader" 30 | ] 31 | }, 32 | { //same as above but for images 33 | test: /\.(png|svg|jpg|gif)$/, 34 | use: [ 35 | 'file-loader' 36 | ] 37 | }, 38 | { //same as above but for fonts 39 | test: /\.(woff|woff2|eot|ttf|otf)$/, 40 | use: [ 41 | 'file-loader' 42 | ] 43 | } 44 | ], 45 | }, 46 | resolve: { 47 | modules: ['node_modules',path.resolve(__dirname, 'build/kotlin-js-min/js/main')], //where to resolve our modules from 48 | alias: { //"Components" is an alias for the "component" folder so we don't have to type out the whole folder path every time 49 | 'Components': path.resolve(__dirname, "src/jsMain/kotlin/com/starter/frontend/component"), 50 | } 51 | }, 52 | devtool: "source-map", // enum // enhance debugging by adding meta info for the browser devtools 53 | // source-map most detailed at the expense of build speed. 54 | context: __dirname, // string (absolute path!) 55 | // the home directory for webpack 56 | // the entry and module.rules.loader option 57 | // is resolved relative to this directory 58 | target: "web", // enum // the environment in which the bundle should run 59 | // changes chunk loading behavior and available modules 60 | // lets you provide options for webpack-serve 61 | stats: "normal", // lets you precisely control what bundle information gets displayed 62 | optimization: { 63 | splitChunks: { //splits into two js files, one for our main code and one for the vendors, like react, kotlin-stdlb, etc. 64 | cacheGroups: { 65 | commons: { 66 | test: /[\\/]node_modules[\\/]/, 67 | name: 'vendors', 68 | chunks: 'all' 69 | } 70 | } 71 | } 72 | }, 73 | plugins: [ 74 | new HtmlWebpackPlugin({ //generates our html file based on a template 75 | title: 'starter', 76 | filename: 'index.html', 77 | template: 'src/jsMain/public/index.html', 78 | unsupportedBrowser: true, 79 | appMountIds: ['root'] 80 | }) 81 | ] 82 | }; -------------------------------------------------------------------------------- /webpack.dev.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const CleanWebpackPlugin = require('clean-webpack-plugin'); 3 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 4 | const WriteFileWebpackPlugin = require('write-file-webpack-plugin'); 5 | const merge = require('webpack-merge'); 6 | 7 | const common = require('./webpack.common.js'); 8 | const devServerContentLocation = 'build/webDevServerTemp'; 9 | 10 | module.exports = merge(common, { 11 | mode: "development", //see https://webpack.js.org/concepts/mode/ 12 | output: { //location to out 13 | // options related to how webpack emits results 14 | path: path.resolve(__dirname, devServerContentLocation), // string 15 | // the target directory for all output files 16 | // must be an absolute path (use the Node.js path module) 17 | "filename": "[name].[chunkhash:8].js" // string // the filename template for entry chunks 18 | }, 19 | devServer: { 20 | proxy: { // proxy URLs to backend development server (great for CORS issues while developing) 21 | // '/api': 'http://localhost:3000' 22 | }, 23 | port: 9000, 24 | contentBase: path.join(__dirname, devServerContentLocation), // boolean | string | array, static file location 25 | compress: false, // enable gzip compression 26 | historyApiFallback: true, // true for index.html upon 404, object for multiple paths 27 | hot: false, // hot module replacement. Depends on HotModuleReplacementPlugin 28 | https: false, // true for self-signed, object for cert authority 29 | noInfo: false, // only errors & warns on hot reload 30 | }, 31 | plugins: [ 32 | new CleanWebpackPlugin([devServerContentLocation]), 33 | new CopyWebpackPlugin( //copy the public files not bundled with webpack, ignore the html template since webpack takes it and generates for us 34 | [{ from: 'src/jsMain/public', to: '', ignore: [ '*.html' ], force: false }],//"to" is '' because it already knows where to output based on content directory 35 | { copyUnmodified: false } 36 | ), 37 | new WriteFileWebpackPlugin() //makes webpack dev-server write the bundles to the file system 38 | ] 39 | }); 40 | -------------------------------------------------------------------------------- /webpack.prod.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const CleanWebpackPlugin = require('clean-webpack-plugin'); 3 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 4 | const merge = require('webpack-merge'); 5 | 6 | const common = require('./webpack.common.js'); 7 | const prodBuildDirectory = 'build/webProd'; 8 | 9 | module.exports = merge(common, { 10 | mode: "production", //see https://webpack.js.org/concepts/mode/ 11 | output: { 12 | // options related to how webpack emits results 13 | path: path.resolve(__dirname, prodBuildDirectory), // string 14 | // the target directory for all output files 15 | // must be an absolute path (use the Node.js path module) 16 | "filename": "[name].[chunkhash:8].js" // string // the filename template for entry chunks 17 | }, 18 | plugins: [ 19 | new CleanWebpackPlugin([prodBuildDirectory]), 20 | new CopyWebpackPlugin(//copy the public files not bundled with webpack, ignore the html template since webpack takes it and generates for us 21 | [{ from: 'src/jsMain/public', to: '', ignore: [ '*.html' ], force: false }], //"to" is '' because it already knows where to output based on content directory 22 | { copyUnmodified: false } 23 | ) 24 | ] 25 | }); --------------------------------------------------------------------------------