https://kotlinlang.org logo
#webassembly
Title
# webassembly
e

eygraber

10/30/2023, 10:07 PM
If I want a shared source set for
js
and
wasmJs
should I just use
wasmJs
and leave out
js
entirely?
a

Artem Kobzar

10/31/2023, 8:19 AM
It depends on the use case. If you have a reach @JsExport API (classes, properties, etc), in this case you still can't drop
js
target, but if you don't have exported declarations or the exported declarations are functions - yes, you can use only
wasmJs
s

Svyatoslav Kuzmich [JB]

10/31/2023, 2:08 PM
wasmJs
is a Kotlin/Wasm target that creates Wasm, which is expected to run in a JS environment.
js
is a Kotlin/JS target that produces JS. You need both if you want to support both JS and Wasm platforms.
e

eygraber

10/31/2023, 3:58 PM
So if my library only supports
wasmJs
and a Kotlin/JS consumer wanted to use it, it wouldn't be able to? i.e. it can't import it and wrap it or something like that?
s

Svyatoslav Kuzmich [JB]

10/31/2023, 4:10 PM
To a large extent yes. Although it is possible, you would need to go through regular JS interop. Your library would need to export functions from Wasm to JS. And Kotlin/JS consumer would need to have
external
declarations describing your API.
5 Views