Is it weird that i just want to write kotlinjs and...
# javascript
n
Is it weird that i just want to write kotlinjs and have it bundled and optimized without having to deal with npm, webpack and configuration files written in js?
😫 1
👀 2
r
Kotlin/JS just isn’t ready.
n
Guess so :/
r
I’ve got something that works here https://github.com/Ribesg/Kita/tree/feature/init
I’m still planning to use it, but you just need to understand how early and undocumented it is. It’s challenging but writing frontend React in Kotlin feels good
s
It is possible but undocumented so pretty frustrating for now indeed, what I did in https://github.com/sdeleuze/spring-messenger/tree/step-4-kotlin-js/frontend could maybe help.
n
i managed to get r.js with almond.js to work i have them in node_modules so that heroku installs them for me
Copy code
val bundleTask = tasks.create("${target.name}Bundle") {
    dependsOn(copyJsTask)
    group = "build"
    val dir = file("build/bundle")
    val outputDir = dir.resolve("out/js/")
    outputs.dir(outputDir.parentFile)
    doLast {
        val inputFolder = dir.resolve("input/")
        inputFolder.deleteRecursively()
        file("build/kotlin-js-min/${target.name}/main/").copyRecursively(inputFolder)
        file("node_modules/almond/almond.js").copyTo(inputFolder.resolve("almond.js"), true)
        outputDir.deleteRecursively()
        outputDir.mkdirs()
        exec {
            workingDir(inputFolder)
            commandLine(
                localBin("r.js"),
                "-o", "baseUrl=.", "name=almond.js",
                "include=penta,almond",
                "insertRequire=penta",
                "out=${outputDir.resolve("bundle.js")}",
                "wrap=true"
            )
            logger.lifecycle(commandLine.joinToString(" "))
        }
        copy {
            from(outputDir)
            from("src/clientJsMain/web")
            into(dir)
        }
    }
}
there are some more tasks..
copyJsTask
extract the dce output and then i use
bundleTask.output
in a copy task this bundles and mangles the javascript code from 20 Mb into a single 2.1 Mb file that can be directly used PS: one could also reference almond.js in the original location, but then the js code will contain the original source location
/home/nikky/dev/....
and although it loads anyways.. i prefer to copy it over and have just a relative reference PPS: if anybody else got something like this working with amd-bundle or similar without the need for almond.js i would really love to see
👍 3
p
@Nikky would you be williing to publish a gist with the full build script for reference?
n
sure https://gist.github.com/NikkyAI/4495e158a53feb5f22295374b38c38d4 you can ignore the proguard stuff (never worked anyways) and most of the second half of the buildscript