Building Golem Components in JavaScript
Building Golem components written in JavaScript requires a series of steps.
If the project was created with golem-cli 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