I’m on a mission to reduce the size of the bundle...
# javascript
a
I’m on a mission to reduce the size of the bundle in my KMM project. I tried
-Xir-property-lazy-initialization
which doesn’t really do anything (actually increases our size). When paired with
-Xir-per-module
it reduces the size by 75%! However, this is only because it’s missing some imports. We use 3 libraries: • Kotlinx serialization • Kotlinx immutable collections • Kotlin stdlib I see 5 JS files as expected (two for serialization) in the build directory but the module JS file only contains this:
Copy code
}(module.exports, require('./kotlin-kotlin-stdlib-js-ir.js'), require('./kotlinx-serialization-kotlinx-serialization-core-js-ir.js')));
So the bundle fails because one of the kotlinx serialization (the JSON part) and the kotlinx immutable is missing from the final, webpacked, JS file. Is this a bug or did I miss something?
a
Hm it probably doesn’t help you, but we use both of those flags (and even have interdependent modules), and our
require
calls come out OK in the end. We don’t use kotlinx immutables, but we do use the core/json serialization modules.
a
Interesting. And it requires both the core and json modules for serialization?
a
Both definitely need to be used. I can’t remember off the top of my head if it’s: myModule requires only json, json requires core OR myModule requires json AND core, json requires core
a
So json requires for for sure, I see that too in the json js file and I depend on both. I'll see if there is an update to either lib and how I depend on it
Ok, so I found the issue. The dependencies are not included because I’m adding them to my
commonMain
sourceset. When In add them explicitly to the
jsMain
sourceset they are correctly imported.
a
interesting! that should probably be flagged as a YT issue
a
Yeah, probably a good idea