The JS DCE seems to not process the stdlib at all....
# javascript
d
The JS DCE seems to not process the stdlib at all. Even with just one kotlin file that has one function in it (no parameters) that returns a string, I get what seems like the entirety of kotlin.js. Am I doing something wrong or is this simply not implemented yet?
b
It's not working properly with new js plugin
Try kotlin-frontend for now
d
I can't use kotlin-frontend, this is multiplatform shared code, to be later used in an angular project
b
Kotlin-frontend works with multimplatform
Essentially you'll need three plugins. Dce, multiplatform and kotlin-frontend
d
Yes, but kotlin-frontend adds webpack and all kinds of dependencies I don't need...
b
Well you do. New js plugin does that too.
How will you get a bundle without webpack?
d
Like I said, this is to be used in a (separate) angular project.
I don't want a bundle here
b
Oh, right. Then use compiled js code in angular and dce it using regular js tools
You don't need kotlin dce in your case
d
Well, it seems like regular js tools cannot see through kotlin.js being completely unused. it ends up in the bundle entirely, because kotlin.js is just one big js file with it's own, proprietary package structure
👍 1
b
Then use frontend for your npm dependencies and dce with it. Ignore webpack stuff if you don't need it. Those will not be included in your post dce files
d
Ok, I will give it a try. However I am skeptical, since in my tests the kotlin-dce does work, just not on kotlin.js. It for example removed unused functions from my code.
i
If I correctly understand you, you need only DCE’d javascript from Kotlin So you can use
nodejs
subtarget (if you don’t want to test you Kotlin/JS in browser), and use task
compileKotlinJs
If you can apply DCE, you need to apply DCE plugin manually, and it should work. After that you can use DCE’d files in your Angular application
d
Yes, I did do that (https://github.com/diesieben07/kotlin-mpp-npm-demo/tree/two-repos, see the mpp subproject). It does produce a
min
version of the code if I run the DCE task, but the DCE'd Kotlin is just the entire stdlib, even though my code is a single function that does not use anything from the stdlib
i
Thank you for your sample, I tried this When I run
runDceJsKotlin
it produces
mpp/build/kotlin-js-min/js/main
folder with
kotlin.js
with size ~119kB which is much smaller than original
kotlin.js
with its size more than 2 MB (you can find it in
build/js/packages_imported/kotlin/1.3.50/kotlin.js
) It seems that DCE works Unfortunately even if you don’t use explicitly some Kotlin’s declarations, it is necessary for some runtime checks and etc
d
Okay, fair, I didn't check it that intensively... Sorry. However: There aren't any runtime checks in my code... There are a lot of functions from the stdlib that are not used in my code that are still in the minified kotlin.js (like for example all the primitive KClass objects are still in there, why?). Seems it's not perfect yet.
i
Yes, you’re right, it’s not perfect yet It is related that DCE works with JavaScript code (not Kotlin code), and it is hard to understand what we can eliminate and what we can’t We are working on its improvement, and some experiments show good results
d
It is related that DCE works with JavaScript code
I see. That explains it. With that it's impressive it works at all 😄
Thanks for the explanations