Hello. I'm planning to share some Code between Bac...
# javascript
d
Hello. I'm planning to share some Code between Backend (Kotlin/JVM, Gradle) and Frontend (Existing Javascript Application, NPM + webpack). I thought using the kotlin multiplatform capabilities to build a library that works on both platforms was a good catch for this problem. I just created a multiplatform gradle-project from IntelliJ and it builds for alle three platforms. But the output for the javascript target is a jar file with the compiled javascript code embedded. I'd like to use the generated javascript code in my existing webapp. Is there any way to configure gradle to output just a commonjs or umd module that I can directly require via webpack? Thanks a lot!
g
As I remember there is some task that only compiles to js
depends on how you want integrate it to your build pipeline
There is kotlin-frontend-plugin that allows to build webpack bundle https://github.com/Kotlin/kotlin-frontend-plugin
a
@d.bellingroth In most cases the
.js
output is located in
build/classes/kotlin/js/main/<module-name>
☝🏻 1
You can tell the compiler to emit commonjs or umd by configuring the
moduleKind
attribute: https://kotlinlang.org/docs/reference/using-gradle.html#attributes-specific-for-js