Getting started | The AssemblyScript Book (original) (raw)

Paving the way to your first AssemblyScript module.

# Setting up a new project

Make sure that a recent version of Node.js (opens new window) and its package manager npm (that comes with Node.js) are installed, then switch to a new directory and initialize a new Node.js module as usual:

Install the AssemblyScript compiler. Let's assume that it is not required in production and make it a development dependency:

Once installed, the compiler provides a handy scaffolding utility to quickly set up a new project, here in the current directory:

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

For completeness, asinit supports the following options:

# Working with your module

The example in assembly/index.ts can now be compiled to WebAssembly by invoking the build command:

Doing so will emit the compiled binaries, bindings and definition files to the build/ directory.

The generated test case in tests/index.js can be executed with:

Once built, the directory contains all the bits to use the module like any other modern Node.js ESM module:

The generated index.html shows how the module can be used on the Web. A web server serving the module directory, defaulting to display index.html, can be started with:

Note that not all of the files may be required depending on the use case, and it is safe to delete what's not needed. If anything goes wrong, asinit can be executed again, which would restore the deleted default files while keeping already edited ones.

# The journey ahead

So far, so good! Now it is time to start editing the project of course, which typically involves:

But that's it already for a quick start. Read on to learn more!