Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ In addition to [Wrangler v2.x](https://github.com/cloudflare/wrangler2) you will

## Wrangler

Configure the [wrangler.toml](wrangler.toml) by filling in the `account_id` from the Workers pages of your Cloudflare Dashboard.
Documentation for Wrangler can be found [here](https://developers.cloudflare.com/workers/tooling/wrangler).

Further documentation for Wrangler can be found [here](https://developers.cloudflare.com/workers/tooling/wrangler).

## Gradle

After setting up Kotlin per the linked instructions above,
To test the build locally, run it in dev.

```
./gradlew :compileProductionExecutableKotlinJs
```shell
wrangler dev
```

That will compile your code and package it into a JavaScript executable, after which you can run `wrangler publish` to push it to Cloudflare.
To deploy the example, use the following command.

```
wrangler publish build/js/packages/kotlin-worker-hello-world/kotlin/kotlin-worker-hello-world.js
```shell
wrangler deploy
```

For more information on interop between Kotlin and Javascript, see the [Kotlin docs](https://kotlinlang.org/docs/reference/js-interop.html). Regarding coroutines, see [this issue and workaround](https://github.com/cloudflare/kotlin-worker-hello-world/issues/2)
For more information on interop between Kotlin and Javascript, see the [Kotlin docs](https://kotlinlang.org/docs/js-interop.html). Regarding coroutines, see [this issue and workaround](https://github.com/cloudflare/kotlin-worker-hello-world/issues/2)
34 changes: 30 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile

plugins {
kotlin("js") version "1.7.10"
kotlin("multiplatform") version "2.2.10"
}

group = "org.example"
Expand All @@ -10,9 +12,33 @@ repositories {
}

kotlin {
js(IR) {
nodejs {
}
js {
nodejs()
binaries.executable()
}
}

// https://kotlinlang.org/docs/js-project-setup.html#support-for-es2015-features
tasks.withType<KotlinJsCompile>().configureEach {
compilerOptions {
target.set("es2015")
}
}

tasks.named("jsProductionExecutableCompileSync") {
val entrypointFile = "${layout.buildDirectory.asFile.get()}/js/packages/kotlin-worker-hello-world/kotlin/kotlin-worker-hello-world.mjs"
outputs.file(entrypointFile)

val jsEntrypoint = """
// The entrypoint expected by Cloudflare
export default {
async fetch(request, env, ctx) {
return HelloWorker.fetch(request, env, ctx);
},
};
""".trimIndent()

doLast {
File(entrypointFile).appendText(jsEntrypoint)
}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
kotlin.code.style=official
kotlin.js.ir.output.granularity=whole-program
kotlin.js.ir.output.granularity=whole-program
org.gradle.configuration-cache=true
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading