How do you guys use Kotlin/JS libraries in other J...
# javascript
e
How do you guys use Kotlin/JS libraries in other JS applications? Does anyone have any experience with that?
👌 3
@turansky do you have any pointers or sample code I could refer to? I’m trying to use some Kotlin/JS code in a Vue+Typescript app and I’m not sure how to properly use the code there as it has some dependencies like the Ktor client.
t
You can create standalone Kotlin/JS libraries on the first step: 1. Mark library methods with DCE 'keep' 2. Use DCE = Kotlin + Kotlin dependencies are inside 3. Fix methods location via webpack if you need (com.example.test.mySuperMethod -> mySuperMethod)
Next steps depend on library type
e
Ah, DCE may have been killing me. Thanks for the tip!
t
ES6 libraries?
DCE can live with ES6 dependencies
WA exists
a
@turansky can you elaborate on
Fix methods location via webpack if you need (com.example.test.mySuperMethod -> mySuperMethod)
?
I'm currently doing some dumb stuff to make top-level package-less aliases in my
jsMain
, but this sounds like it might be smarter 😅
Copy code
// webpack.config.d/output.js
config.output.libraryTarget = 'umd';
config.output.libraryExport = ['com', 'example', 'test', 'mySuperMethod'];
a
Iiinteresting, thanks for that. Do you do this in the JS code that's consuming your Kotlin/JS library, or do you do it as part of building your Kotlin/JS library?
t
It is part of library building. Kotlin/JS library output - single class (Web component in our case).
i
@ankushg @Evan R. Please consider that webpack’s
output.library
properties works incorrectly when source maps enabled in Kotlin/JS until 1.3.50 https://youtrack.jetbrains.com/issue/KT-33288
e
Thanks for the tip Ilya!