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/dynamicwill be loaded dynamically./modules/indexis the entry point with amain()function that loadsdynamicdynamically./modules/sharedwill be shared bydynamicandindexwithout duplicating code.
/webpack.config.d/configuration.jsdefines theindexmodule 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_dynamicin this example). @EagerInitializationmust be used as a workaround to execute logic when loading a module, e.g. theindex.