Welcome to the new Golem Cloud Docs! 👋
JavaScript Language Guide
Building Components

Building Golem Components in JavaScript

Building Golem components having an application manifest is straightforward, just use the golem command line interface:

golem app build

If the project was created using golem app new as recommended, the golem app build command will always work as expected.

The result of the golem app build command is a WebAssembly component file ready to be uploaded to Golem. It does not have to be specified explicitly, as the golem tool will automatically find the correct file when doing for example:

golem component add

Under the hood

Building Golem components written in JavaScript requires a series of steps.

If the project was created with golem app new, it already has a package.json that incorporates all the necessary steps as npm scripts to build the component, so it is enough to run:

npm run componentize

In details, building the component requires the following steps:

Compile the JavaScript code to JavaScript

The examples use rollup through an npm script:

$ npm run build

This will compile all the JavaScript sources into a single JavaScript file at out/main.js.

Componentizing the JavaScript code

The final step is componentizing, which involves:

  • embedding our JavaScript code into the StarlingMonkey JS engine
  • running Wizer pre-initialization, which pre-loads and parses our Javascript source in the JS engine
  • creating the wasm output file for our component with it's interface exposed as a WebAssembly component usable by Golem.

The example projects includes an npm script called componentize, which also includes the previous build step.

$ npm run componentize

The output wasm file with be created with the built component name, eg.: out/example.wasm.

The above npm script will execute the following commands:

$ npm run build && jco componentize -w wit -o out/example.wasm out/main.js