Stefan Beyer
03/26/2020, 8:56 AM@JsExport
annotation is throwning a wrench into my project. Maybe you folks have an idea on how to do this correctly?
My goal is to have a Kotlin common sorce set, which should be compiled to js and jvm. This will be a common library, that will be used by the frontend (React with TypeScript) and the backend (Spring Boot with Kotlin) and will contain common data structures, validation logic and some particularly complex bits of business logic that need to be executed on both platforms.
Now my train of thought was to just implement all of this in the commonMain source set and leave the jsMain and jvmMain source sets empty. This works fine for the jvm target: I get a .jar file with all the classes and functions defined in the common code. But for js, everything that should be exported needs to be annotated with @JsExport
for it to actually being compiled to js. Does this mean I have to populate the jsMain source set with a wrapper for each class and function that exists in commonMain, just to be able to compile this to js? This does not sound very pragmatic. is there maybe a way to tell the compiler to always export classes and functions from a certain package?Big Chungus
03/26/2020, 9:01 AMBig Chungus
03/26/2020, 9:01 AMexpect annotation class JsExport
and typealias it on js sourceSetBig Chungus
03/26/2020, 9:02 AMStefan Beyer
03/26/2020, 9:03 AMBig Chungus
03/26/2020, 9:03 AM//Common
expect annotation class JsExport
//JVM
actual annotation class JsExport
//JS
actual typealias JsExport = kotlin.js.JsExport
Big Chungus
03/26/2020, 9:04 AMIlya Goncharov [JB]
03/26/2020, 9:11 AMStefan Beyer
03/26/2020, 9:23 AM//Common
expect annotation class Export()
//JVM
actual annotation class Export
//JS
actual typealias Export = JsExport
without the explicit empty constructor, there is an error at commonMain use sites:russhwolf
03/26/2020, 12:05 PM@OptionalExpectation
to the declaration in common and then you don't need anything in jvm (or any other platform you add later)Big Chungus
03/26/2020, 12:09 PMrusshwolf
03/26/2020, 12:18 PMrusshwolf
03/26/2020, 12:18 PMbashor
03/26/2020, 12:47 PM