Have there been any comparisons for how large a ko...
# javascript
s
Have there been any comparisons for how large a kotlin-js application is after DCE compared to the equivalent Typescript?
4
t
I have made a quick todo app using an existing repo. The only library used are lodash (one function) and kotlinx.html Gzipped. But I am sure I don’t have the best optimisations.
👍 1
🆒 1
s
157 kb? That's not bad.
b
@Tristan Caron good job, thank you!
Also, the result could be improved by using some minifier, like UglifyJS2.
t
Well, it doesn’t work for me 🤔 (I was sure I configured it) But someone else did it too, and apparently succeeded to get 47 kb for the some project 👏 https://www.kotlindevelopment.com/eliminate-dead-code-kotlin/
g
This is quite old but with uglify + gzip we are around 50 Kb : https://data2viz.github.io/data2viz/ex-force-js/index.html
😲 1
👍 2
s
wow, that's pretty good. With sizes like this, once Kotlin-js exports typescript definitions, I won't have any trouble getting them on-board with sharing models and api logic.
t
My team is not switching to it for one reason... Lazy loading (deferred import) and I am not sure there is an easy way to do it.
b
@Tristan Caron could you please provide more info about your case? You can declare own external require and use it, but probably it will be less convenient.
t
I will provide you a concrete example and maybe you will be able to suggest a better solution 🙂 Thanks for your help.
@bashor So 🙂 I have a project with two modules. A and B. A is my main project. I have an
index.html
file which is running my code.
Copy code
import kotlin.browser.document
import kotlin.browser.window

fun main() {
    window.alert("Hello World!")

    document.getElementById("my-button")?.addEventListener("click", {
        deferredHello()
    }, null)
}
deferredHello()
is coming from module B. I don’t expect this code to work, but too fail when in click on the button. However, it’s failing before, because the compiled code look like this
Copy code
(function (_, Kotlin, $module$deferredapp) {
  'use strict';
  var deferredHello = $module$deferredapp.deferredHello;
  var Unit = Kotlin.kotlin.Unit;
  function main$lambda(it) {
    deferredHello();
    return Unit;
  }
  function main() {
    var tmp$;
    window.alert('Hello World!');
    (tmp$ = document.getElementById('my-button')) != null ? (tmp$.addEventListener('click', main$lambda, null), Unit) : null;
  }
  _.main = main;
  main();
  Kotlin.defineModule('mainapp', _);
  return _;
}(module.exports, require('kotlin'), require('deferredapp')));

//# sourceMappingURL=mainapp.js.map
And deferred doesn’t exist yet.
In my code I should have something like:
Copy code
require("B.js").then(module => {
    module.deferredHello()
})
But it won’t work of course