This is a rough proof-of-concept that a Kotlin/JS browser app can be split into multiple chunks that can depend on each other dynamically. For example a Kotlin React app could be split into multiple smaller JS files that way.
/
compiles all submodules into separate JS files./modules/dynamic
will be loaded dynamically./modules/index
is the entry point with amain()
function that loadsdynamic
dynamically./modules/shared
will be shared bydynamic
andindex
without duplicating code.
/webpack.config.d/configuration.js
defines theindex
module as the entry point for the library.
- Only works with the JS IR compiler.
- The setup is fragile and can break with subsequent Kotlin updates.
- Dynamic imports have unstable names (like
kotlin_kjs_chunks_dynamic
in this example). @EagerInitialization
must be used as a workaround to execute logic when loading a module, e.g. theindex
.