dpux
05/17/2020, 8:04 PMSean Keane
05/17/2020, 8:09 PMpackage.json
to the distribution folder. For this to work I think you need to target the browser. Once built you can just run npm publish
in the distributions and it should publish as normal with the config of the package.jsondpux
05/17/2020, 8:37 PMSean Keane
05/17/2020, 8:40 PM//Export common as common
const common = require("./common.js");
module.exports = {
common: common
};
Now, your actual code which you have should live as a kotlin file in the subdirectory for your source. You need to annotate them to make it available as an export like this.
@JsExport
class Person {
fun helloPerson(name: String): String {
return "helloPerson: $name"
}
}
@JsExport
fun globalHello(name: String): String {
return "globalHello: $name"
}
That should make them visible from TS/JS when you import the module from NPM :)dpux
05/17/2020, 8:42 PMSean Keane
05/17/2020, 8:43 PMSean Keane
05/17/2020, 8:44 PMdpux
05/17/2020, 8:44 PMdpux
05/17/2020, 9:33 PMdpux
05/17/2020, 9:34 PMSean Keane
05/18/2020, 11:29 AMimport { libkjs } from 'libkjs'
Then you can call the function from the import.
var msg = libkjs.globalHello("From React View")
The JsExport exposes the function for use, the index.js exposes the library to use it.Andrew
05/18/2020, 3:56 PMdpux
05/18/2020, 4:31 PMSean Keane
05/18/2020, 4:32 PMdpux
05/18/2020, 4:32 PMSean Keane
05/18/2020, 4:32 PMdpux
05/18/2020, 4:35 PMdpux
05/18/2020, 4:36 PMSean Keane
05/18/2020, 4:36 PMSean Keane
05/18/2020, 4:38 PMdpux
05/18/2020, 4:39 PMSean Keane
05/18/2020, 4:39 PMdpux
05/18/2020, 4:41 PMdpux
05/18/2020, 6:45 PM