Kotlin - How to import node packages?
Clash Royale CLAN TAG#URR8PPP
Kotlin - How to import node packages?
I am developing a web application using Kotlin to build its front-end.
I want to be able to import npm packages so I can use them in my Kotlin code. I can't find an example on how to do this. There are examples on how to generate npm packages from Kotlin, but not how to USE them in your Kotlin code.
I would also be happy if I could import Java libraries, use them in my Kotlin code and compile it down to JavaScript, but that does not seem to be possible yet, which is why I want to import npm code instead.
Also kotlinlang.org/docs/reference/js-interop.html
– Mikhail
May 26 '17 at 2:07
2 Answers
2
Kotlin front-end Gradle plugin does just what you are asking.
You can add NPM dependencies to the Gradle build as:
kotlinFrontend
npm
dependency "style-loader" // production dependency
devDependency "karma" // development dependency
And there are even full stack examples using this.
assuming you'd want the equivalent of
import Express from "express"
you would do this in Kotlin
@JsModule("express")
external class Express // if Express is a class in its module
which means, if its a function you are looking for say
import dollface from "dolly"
you would define it in kotlin as
@JsModule("dolly")
external fun dollface(faceColor: String)
See more elaborations here
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I would delete the part about Java libraries, because it looks like you're asking too very different things.
– Mikhail
May 26 '17 at 2:06