https://github.com/golemcloud/sbt-wasm-component
Create easily your Golem workers from Scala
https://github.com/golemcloud/sbt-wasm-component
golem golem-cloud scala scala-plugin
Last synced: 2 months ago
JSON representation
Create easily your Golem workers from Scala
- Host: GitHub
- URL: https://github.com/golemcloud/sbt-wasm-component
- Owner: golemcloud
- Created: 2023-10-05T19:10:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-10T18:04:51.000Z (12 months ago)
- Last Synced: 2024-05-11T01:26:26.807Z (12 months ago)
- Topics: golem, golem-cloud, scala, scala-plugin
- Language: Scala
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 7
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
sbt-wasm-component
==================Avoid any boilerplate in your project by using just one annotation to export your Golem worker from Scala to JS.
Setup
-----Add sbt-wasm-component as a dependency in `project/plugins.sbt`:
```scala
addSbtPlugin("cloud.golem" % "sbt-wasm-component" % "x.y.z")
```Usage
-----The WASM component plugin is automatically loaded, it just needs to be enabled with `enablePlugins(WasmComponentPlugin)` in your `build.sbt`:
```scala
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.13"lazy val root = (project in file("."))
.enablePlugins(WasmComponentPlugin)
```Then you will be able to annotate your Golem worker object with the `@cloud.golem.WitExport` annotation:
```scala
package example@cloud.golem.WitExport
object ShoppingCart { self =>def initializeCart(userId: String): String = {
println(s"Initializing cart for user $userId")
if (math.random() > 0.1) userId
else "Error while initializing cart"
}
// ...}
```
Once done that, it will be enough to run `sbt wasmComponent` and the plugin will take care of exporting your worker in WASM.