Is their a way when generating JS libraries from K...
# javascript
s
Is their a way when generating JS libraries from KMP that will eventually be published to npm to not bundle ANY of it’s dependencies? like ktor/kotlin-stdlib And instead give them as runtime dependencies? (dependencies in package.json) The default behaviour seems to bundle everything which I don’t get the reasoning for.. if it’s possible then is there a downside?
e
It's not possible because generated JS code doesn't use stable names for non-`@JsExport`ed declarations (yet?). That means if you compile library A and publish it to npm, and then you compile library B (dependsOn) A and publish it to npm, the B to A bindings won't match.
Currently, every published module will have duplicated dependencies, to some degree. DCE will remove what's unused for the single module, so one might ship more, another might ship less.
And DCE is another topic. You'd have to completely disable it when publishing the module to npm. Each module would have to export everything.
Kotlin's stdlib would probably get you a 5 MB package.
s
ooo yes .. makes sense also tells why possible when we use npm dependencies (where we define external jsmodules)
my current setup let’s kotlin generate the library, ts files and source maps then I give it to rollup to minify(inheriting the original source map) and then publish to npm (internal orgs) reduces library bundle size by quite a bit (2-3x) with stdlib/serialisation and few others dependencies it’s well under 400KB for production builds (from ~1.2MB, my code is less than 10% of that)
e
I mean, what you're asking for doesn't seem entirely impossible. It would definitely be nice to properly split up dependencies when publishing to package managers, as that would create a more familiar environment for those that come from the JS ecosystem. But I was just thinking about how all of this could be done on the tooling side, and there seems to be many scenarios I wouldn't be sure how to tackle.
Kotlin stdlib is actually published to npm. Publishing was removed in v2.0+ IIRC https://github.com/JetBrains/kotlin/commit/3d399a8b25e55fb2d816c187c0b9aaa16ccd9b7e https://www.npmjs.com/package/kotlin
s
yeah.. got the reasoning the first time just added-on on how i’m tackling the bundle size bloat