Defining Golem Components in Scala.js
Creating a project
Golem's command line interface provides a set of predefined, Golem-specific templates to choose from as a starting point.
To get started from scratch, first create a new application using the Scala.js template:
golem app new my-app scalajs
cd my-appAn application can consist of multiple components. Add a new component by choosing from one of the available templates. To see the list of available templates, run:
golem component newThen create a new component using the chosen template:
golem component new scalajs my-componentSpecification-first approach
Golem and the Scala.js toolchain currently requires defining the component's interface using the WebAssembly Interface Type (WIT) format. See the official documentation of this format (opens in a new tab) for reference.
Each new project generated with golem contains a wit directory with at least one .wit file defining a world. This world can contain exports (exported functions and interfaces) and these exports will be the compiled Golem component's public API.
When a component is compiled (see the Building Components page for details), a couple of scala packages get generated in the target/<scala version>/src_managed directory. These packages contains the Scala definitions of all the data types and interfaces defined in the WIT file(s).
To implement the specification written in WIT, the Scala.js code must implement some of these generated exported traits with proper @JSExport annotations.