sunnat629
03/03/2024, 10:09 PMsunnat629
03/03/2024, 10:09 PMshared
module
@OptIn(ExperimentalJsExport::class)
@JsExport
class MathOp {
fun add(a: Int, b: Int): Int = a + b
fun sub(a: Int, b: Int): Int = a - b
}
build gradle shared module
js(IR) {
moduleName = "shared"
browser {
webpackTask {
}
testTask {
useKarma {
useSafari()
useFirefox()
useChrome()
useChromeCanary()
useChromeHeadless()
webpackConfig.cssSupport { enabled.set(true) }
}
}
}
binaries.executable()
}
in jsMain>kotlin>App.js
is working
fun main() {
...
val timelineElement = document.getElementById("timeline")
timelineElement?.textContent = result
...
}
I want to use the converted function in jsMain>resources>main.js
and execute in index.html
. But somehow I can connect my shared.js
?turansky
03/03/2024, 11:48 PM<script type="module">
import { MathOp } from './shared.mjs'
MathOp.add(...)
<script>
Artem Kobzar
03/04/2024, 9:33 AM