let's say I put this into jsMain/resources/script....
# javascript
b
let's say I put this into jsMain/resources/script.js
Copy code
export function add(a, b) {
    return a + b;
}
how do I access this in my Kotlin code? I've tried
Copy code
@JsModule("./script.js")
@JsNonModule
external fun add(a: Int, b: Int): Int
but this does not actually bundle nor load the file and tells me that function add is undefined
1
t
Copy code
@file:JsModule("./script.js")

external fun add(a: Int, b: Int): Int
If file in resources:
Copy code
@file:JsModule("script.js")

external fun add(a: Int, b: Int): Int
b
does not compile for me
ah, have to remove the package
t
Copy code
@file:JsModule("script.js")

package at.fyayc
 
external fun add(a: Int, b: Int): Int
b
Copy code
@file:JsModule("./script.js")
@file:JsNonModule

package at.fyayc

external fun add(a: Int, b: Int): Int
thank you, got it working
t
> @file:JsNonModule You can use
moduleKind = "es"
or
moduleKind = "commonjs"
to avoid this annotation It has no sense 😞
b
where do I define that? in gradle?
t
> in gradle? Yes
b
thank you
looks like that one has been changed to
Copy code
kotlin {
    js {
        compilerOptions {
            moduleKind = JsModuleKind.MODULE_ES
        }
    }
}
thanks, that works
so I suppose this generates esmodules for everything using the Kotlin compiler, then it is down leveled to commonjs using webpack?
t
From
es
you can build/bundle any other module kind
By default Webpack bundle UMD module
b
thank you