hfhbd
09/25/2023, 10:44 AMEdoardo Luppi
09/25/2023, 11:29 AMhfhbd
09/25/2023, 11:34 AMEdoardo Luppi
09/25/2023, 11:36 AMhfhbd
09/25/2023, 11:38 AMjw
09/25/2023, 11:42 AMkotlin.js.ir.output.granularity=whole-program
Edoardo Luppi
09/25/2023, 11:44 AMjw
09/25/2023, 11:45 AMEdoardo Luppi
09/25/2023, 11:46 AMhfhbd
09/25/2023, 11:46 AMjw
09/25/2023, 11:53 AMhfhbd
09/25/2023, 11:57 AMI don't care
option? 😄
I just want to write this js, generate 1 file and pass the call function to the jvm host:
function foo(message) { return message.bar; }
Thankfully, I finally get 1 js file, nice.
But the resulting js file still uses exports and there is no "static" entrypoint.Edoardo Luppi
09/25/2023, 11:58 AMhfhbd
09/25/2023, 12:01 PMEdoardo Luppi
09/25/2023, 12:02 PMjw
09/25/2023, 12:07 PMhfhbd
09/28/2023, 7:47 AMwhole-options
which works nice, and this setup:
kotlin {
js(IR) {
nodejs {
binaries.library()
useCommonJs()
}
}
}
@JsExport
fun foo(message: dynamic) {
println("asdf")
}
The resulting js file contains modules and the used js engine does not support it:
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: ReferenceError: "module" is not defined. (//src/main/resources/script/test-javascript.js#1) in //src/main/resources/script/test-javascript.js at line number 1, cause: org.mozilla.javascript.EcmaError: ReferenceError: "module" is not defined. (//src/main/resources/script/test-javascript.js#1)
Do you know any option to not use modules at all? this is the failing last line: }(module.exports));
kotlin {
js(IR) {
nodejs {
binaries.library()
configurePlainOptions()
}
}
}
fun KotlinJsTargetDsl.configurePlainOptions() {
compilations.configureEach {
kotlinOptions.configurePlainOptions()
binaries
.withType(JsIrBinary::class.java)
.configureEach {
linkTask.configure {
kotlinOptions.configurePlainOptions()
}
}
}
}
fun KotlinJsOptions.configurePlainOptions() {
moduleKind = "plain"
sourceMap = true
sourceMapEmbedSources = "never"
}
You need to not only configure the kotlinCompileJs task but the binaries too, so I just copied the useCommonJS()
implementation and replaced the moduleKind to plain
. Now I need to add a top level function, but this is easy with Gradle using a copy task, because the host (using Rhino 1.7R4) only supports a toplevel function.Edoardo Luppi
09/28/2023, 10:21 AM