K/JS dependencies are similar to K/JVM dependencies. By adding them to the gradle project you use and compile them. But to run the project you need the runtime dependency. The default run
task in K/JVM automatically adds the runtime dependencies to the classpath. But if you want to create a jar you have to do this manually or create a fat jar.
In K/JS (for browser, not sure about nodejs) their is no default run task that includes the runtime dependencies. You have to add them manually. Their are two ways to do it.
- Manually grep the dependency js files from the
runtimeClasspath
task
- Use the webpack build (similar to the fat jar approach)
Here is a working example for the webpack build. The build
task creates the artefacts at ./build/distributions/
. (Their is also a run
task that starts a server at port 8080)
build.gradle.kts
plugins {
kotlin("js") version "1.3.72"
}
repositories {
mavenCentral()
maven("https://dl.bintray.com/nwillc/maven")
}
dependencies {
implementation(kotlin("stdlib-js"))
testImplementation(kotlin("test-js"))
implementation("com.github.nwillc:ksvg-js:3.0.0")
}
kotlin.target.browser {}
main.kt
import com.github.nwillc.ksvg.elements.SVG
import kotlin.browser.document
fun main() {
val svg = SVG.svg(false) {
circle {
cssClass = "black-stroke"
id = "face"
cx = "180"
cy = "140"
r = "80"
fill = "#aa450f"
}
}
document.write(svg.toString())
}