This repository contains a minimal example of how to do code splitting in Kotlin/JS.
To build: ./gradlew build
To run in the Node.js repl:
node
const mainModule = await import(
    "./build/kotlin-webpack/js/productionExecutable/codesplitting.js"
)
mainModule.main()Main.kt asynchronously imports fun chair from Chair.kt. Code splitting
is taking placing: there are two JavaScript files.
Main.kt directly imports fun kofi from Kofi.kt. No code splitting
takes place, the code ends up in the same JavaScript file.
Essential elements needed to make this work:
// build.gradle.kts
kotlin {
    compilerOptions {
        // Compile each .kt file to a separate .mjs file
        compilerOptions.freeCompilerArgs.add("-Xir-per-file")
    }
}// Chair.kt
@JsExport
fun chair() {
    /* ... */
}// Main.kt
importAsync<ChairModule>("./Chair.export.mjs")
    .then { it.chair() }// webpack.config.d/codesplitting.js
config.entry = {
    main: require('path').resolve(
        __dirname, 
        "kotlin/codesplitting/com/zenmo/Main.export.mjs"
    )
}