Uses Vercel's NCC tool to bundle the produced NodeJS executable with all its dependencies. There are two plugins provided:
org.araqnid.kotlin-nodejs-application
will build a ZIP archive of the bundled executable. This will contain anindex.js
and the contents can just be run bynode
after unpacking.org.araqnid.kotlin-github-action
will write the bundled executable to thedist
directory. 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("js")
id("org.araqnid.kotlin-nodejs-application") version "0.0.4"
}
kotlin {
js(IR) {
nodejs {}
binaries.executable()
useCommonJs()
}
}
dependencies {
}
nodeJsApplication {
// defaults
nccVersion.set("latest")
minify.set(true)
v8cache.set(false)
target.set("")
sourceMap.set(true)
// moduleName.set("project-name") // shouldn't be necessary
// externalModules.add("aws-sdk") // would expect aws-sdk to be installed globally when executed
}
In build.gradle.kts
:
plugins {
kotlin("js")
id("org.araqnid.kotlin-github-action") version "0.0.4"
}
kotlin {
js(IR) {
nodejs {}
binaries.executable()
useCommonJs()
}
}
dependencies {
}
actionPackaging {
// defaults
nccVersion.set("latest")
minify.set(true)
target.set("")
sourceMap.set(false)
// moduleName.set("action-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").