Quick start

Paving the way to what might be your first WebAssembly module.

To get started with AssemblyScript, switch to a new directory and install the compiler from npm‚Äč

$> npm install --save-dev assemblyscript

If you need a specific version of the compiler, append the respective version number as usual. The latest nightly version can be obtained via --save-exact assemblyscript@nightly.

followed by scaffolding a new project, for example in the current directory:

$> npx asinit .

The asinit command automatically creates the recommended directory structure and configuration files, including:

  • The assembly/ directory containing the sources being compiled to WebAssembly, with a tsconfig.json telling your editor about AssemblyScript's standard library and an index.ts to get you started.

  • The build/ directory where compiled WebAssembly binaries, source maps, definition files etc. become placed.

  • A package.json with AssemblyScript as a development dependency and build tasks to compile both an untouched (as emitted by the AssemblyScript compiler) and an optimized (using Binaryen) version of your program in both binary and text format.

Afterwards, edit the sources in assembly/, maybe tweak the build steps in package.json to fit your needs, and run npm run asbuild to compile your program to WebAssembly.

Using index.js in the root directory of your package to instantiate and export the WebAssembly module you'll then be able to requireit just like any other node module, with the notable difference that the only values your module's exports understand being integers and floats. Read on to learn more!

Edit on GitHub