https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

altavir

07/19/2019, 7:50 AM
Do anybody have a build sample with new mpp with webpack bundle?
s

snrostov

07/19/2019, 8:51 AM
Webpack bundle should work without configuration out of the box. Just add
browser()
inside
js {  }
target preset.
./gradlew build
will build js bundle into
build/distributions
folder. Sample project can be created with wizard: -
Gradle
->
Kotlin/JS for browser
(don’t forget to uncheck
Java
). Also in the resulting project you can just
./gradlew run
to start webpack dev server and open page in browser. -
Kotlin
->
JS Client and JVM Server | Gradle
will create project with ktor and js frontend. Same sample here: https://github.com/ktorio/ktor-samples/tree/master/mpp/fullstack-mpp
a

altavir

07/19/2019, 10:04 AM
The example does not include dce. Is it possible to use it with mpp?
s

snrostov

07/19/2019, 10:05 AM
currently it is not supported. https://youtrack.jetbrains.com/issue/KT-32323
a

altavir

07/19/2019, 10:06 AM
OK then, I will try to use webpack production mode then. I guess that webpack run mode is also not supported?
s

snrostov

07/19/2019, 10:08 AM
yes, there is no such option in webpack task yet, but as a workaround you can add custom configuration in
webpack.config.d/mode.js
with this contents:
Copy code
config.mode = 'production'
a

altavir

07/19/2019, 10:09 AM
thanks
For some reason it embeds source map even if I ask not to do so...
s

snrostov

07/19/2019, 10:16 AM
You mean source maps?
a

altavir

07/19/2019, 10:16 AM
yes. The resulting js weights 11 Mb and has source maps embedded. I will try clean build
s

snrostov

07/19/2019, 10:18 AM
yes, it is enabled by default. you can disable it by setting
sourceMaps = false
in
webpackTask {}
a

altavir

07/19/2019, 10:23 AM
does not work with groovy configuration.
s

snrostov

07/19/2019, 10:24 AM
looks like a bug, will check. please fill issue if you can
It works for me:
Copy code
kotlin {
    target {
        browser {
            webpackTask {
                sourceMaps = false
            }
Can you please show your build.gradle?
a

altavir

07/19/2019, 10:44 AM
You seem to be using
kotlin-js
plugin. I am talking about mpp:
Copy code
kotlin {
    jvm {
        withJava()
        compilations.all {
            kotlinOptions {
                jvmTarget = "1.8"
            }
        }
    }

    js {
        browser()
        compilations.all {
            kotlinOptions {
                sourceMap = true
                sourceMapEmbedSources = "always"
                moduleKind = "commonjs"
            }
        }
    }
s

snrostov

07/19/2019, 10:45 AM
It works with mpp too:
Copy code
kotlin {
    js {
        browser {
            webpackTask {
                sourceMaps = false
            }
a

altavir

07/19/2019, 10:45 AM
Let me check it again
s

snrostov

07/19/2019, 10:45 AM
note:
sourceMapEmbedSources = "always"
is not required
sourceMap = true
is by default since 1.3.40
and there is
useCommonJs()
shortcut that you can use instead of
Copy code
compilations.all {
  kotlinOptions {
    moduleKind = "commonjs"
a

altavir

07/19/2019, 10:47 AM
Copy code
js {
        browser{
            webpackTask {
                sourceMaps = false
            }
        }
        compilations.all {
            kotlinOptions {
                moduleKind = "commonjs"
            }
        }
    }
Copy code
A problem occurred evaluating root project 'bmn-scheduler-mp'.
> Could not set unknown property 'sourceMaps' for task ':jsBrowserTest' of type org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest.
s

snrostov

07/19/2019, 10:47 AM
Ah, sorry, this is a bug that was fixed in my branch but not in 1.3.50-eap1. Will be fixed in eap2
a

altavir

07/19/2019, 10:48 AM
OK. Can I configure the source maps directly through webpack configuration? 11 Mb bundle is not what I like to have
s

snrostov

07/19/2019, 10:49 AM
You can add this at the bottom of script:
Copy code
tasks {
    jsBrowserWebpack {
        sourceMaps = false
    }
}
a

altavir

07/19/2019, 10:53 AM
OK, it worked. 3Mb is large but still better than 11 Mb. Kotlin stdlib seems to be taking the most of remaining buindle. Is it possible to apply dce manually?
s

snrostov

07/19/2019, 10:53 AM
Yes, but it is too tricky.
a

altavir

07/19/2019, 10:53 AM
OK. I will wait then. Do not need this one in production yet
3 Views