Uses Vercel's NCC tool to bundle the produced NodeJS executable with all its dependencies. There are two plugins provided:
org.araqnid.kotlin-nodejs-applicationwill build a ZIP archive of the bundled executable. This will contain anindex.jsand the contents can just be run bynodeafter unpacking.org.araqnid.kotlin-github-actionwill write the bundled executable to thedistdirectory. This can then be checked in to the repo, which is how GitHub Actions expects to fetch executable scripts.
When using org.araqnid.kotlin-nodejs-application, a .nvmrc file will be inserted into the produced archive to
indicate which version of Node the bundle was built with.
The bundling will be added as a dependency of the assemble task.
In build.gradle.kts:
plugins {
kotlin("multiplatform") version "2.2.21"
id("org.araqnid.kotlin-nodejs-application") version "0.1.0"
}
kotlin {
js {
nodejs {}
binaries.executable()
useCommonJs()
}
}
repositories {
mavenCentral()
}
dependencies {
}
nodeJsApplication {
// defaults
nccVersion = "latest"
minify = true
v8cache = false
target = ""
sourceMap = true
// moduleName = "project-name" // shouldn't be necessary
// externalModules.add("aws-sdk") // would expect aws-sdk to be installed globally when executed
}In src/jsMain/Example.kt:
fun main() {
println("hello world")
}In build.gradle.kts:
plugins {
kotlin("multiplatform") version "2.2.21"
id("org.araqnid.kotlin-github-action") version "0.1.0"
}
kotlin {
js {
nodejs {}
binaries.executable()
useCommonJs()
}
}
repositories {
mavenCentral()
}
dependencies {
}
actionPackaging {
// defaults
nccVersion = "latest"
minify = true
target = ""
sourceMap = false
// moduleName = "project-name" // shouldn't be necessary
// externalModules.add("@actions/core") // would expect to use @actions/core installed on the runner
}The plugins define either a nodeJsApplication or actionPackaging extension respectively to receive settings. Most of
the settings correspond to options to pass to NCC.
Produce a V8 cache file (save some startup time) (nodeJsApplication only).
Minify bundled Javascript. Licenses will be extracted to a LICENSE.txt file in the Zip file.
Specify target ES variant (see https://webpack.js.org/configuration/target)
Produce a source map alongside the runnable script.
Configure external modules that will not be included in the bundle.
Must match the root name of the JavaScript produced by the Kotlin compiler. The plugin will try to glean this from the compilation task.
Version of NCC to use (defaults to "latest").