I want to release a Kotlin/JS module that can be u...
# getting-started
j
I want to release a Kotlin/JS module that can be used by other Kotlin projects. One of my worries is that I will have to be declaring external functions for each of the projects using the kotlin library. How should I go on about this?
h
You don't need to mark your functions if you only want to consume it from other Kotlin/JS modules, beside change the visibility to
public
of course.
j
How would I go on about publishing a js package to npm to be consumed by other Kotlin (js) projects without having to declare externals?
a
you just have to export them by marking hem with
@JsExport
annotation
j
How would I import this without having to declare externals in another project?
a
import is
kotlin.js.JsExport
h
You want to write a Kotlin/JS library, export it as JS (via npm) and consume the npm package by another Kotlin/JS project? This is technically possibly using JsExport, but the JS export lacks many Kotlin types and feature, like kotlin.Long, so you need many workarounds. To consume a Kotlin/JS library you should depend on the published jar file instead.
j
Thank you @hfhbd! Will it produce a jar file that can be consumed by another Kotlin.js project?
h
Yes
👀 1