jean
03/04/2025, 11:46 AMjs(IR) {
browser {
webpackTask {
mainOutputFileName = "kmp_lib.js"
output.library = "kmpLib"
}
}
binaries.executable()
generateTypeScriptDefinitions()
}
When I run ./gradlew jsBrowserProductionWebpack
I see that my_module.js
and kmp_lib.js
are generated but the content seems weird
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.my_module=o():e.my_module=o()}(globalThis,(()=>(()=>{"use strict";var e={};return(e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})})(e),e})()));
I was expecting a js file containing all the public classes/variable exposed in my module, the same way it works for Apple. What am I missing?Artem Kobzar
03/04/2025, 12:54 PM@JsExport
annotation, which will make them visible in your JavaScript application.
The documentation is here: https://kotlinlang.org/docs/js-to-kotlin-interop.htmljean
03/04/2025, 12:55 PMEdoardo Luppi
03/04/2025, 2:08 PMbinaries.executable
at this point tho.
If I'm building a self contained executable application, why would I want to
1. generate TS types
2. avoid minificationjean
03/04/2025, 2:14 PMbinaries.exectuable
then? I added typescript generation since the web app client I'm considering adding the library to is written with TSEdoardo Luppi
03/04/2025, 2:17 PMbinaries.library
for this.
You also don't need Webpack at that point, since bundling shouldn't be done at the library level, but at the final consumer level. A library doesn't configure Webpack at all, so you'd be good to go.
You will have to mark your API surface with @JsExport
anyway, as that's how you prevent name mangling.
Note that the API can be a subset of the Kotlin declarations, you don't need to export everything.jean
03/04/2025, 2:19 PMEdoardo Luppi
03/04/2025, 2:21 PMjean
03/04/2025, 2:23 PMbinaries.library
mentioned anywhere.