@szacskesz/as-loader
TypeScript icon, indicating that this package has built-in type declarations

0.27.6-RC-4 • Public • Published
AssemblyScript logo webpack logo

as-loader

AssemblyScript loader for webpack

npm version

Installation

This loader requires AssemblyScript >= 0.27.1, Node.js >= 12 and webpack 5

# Install as an alias
npm install as-loader@npm:@szacskesz/as-loader
npm install --save-dev assemblyscript

The minimal webpack.config.js:

module.exports = {
  entry: "src/index.ts",
  resolve: {
    extensions: [".ts", ".js"],
  },
  module: {
    rules: [
      {
        // Can use any pattern if it ends with ".ts" or ".tsx"
        test: /\.asc\.ts?$/,
        loader: "as-loader",
        options: {
          // Other assemblyscript compiler options...
        },
      },
      // If you use typescript files too
      {
        test: /\.ts$/,
        exclude: [/\.asc\.ts?$/],
        loader: "ts-loader",
      },
    ],
  },
};

Usage

By default, the loader emits a .wasm file (+ .wasm.map if source maps are enabled) and creates a CommonJS module that exports the URL to the emitted .wasm file and the raw bindings's instantiate function.

To simplify loading logic, you can use the instantiateModule function from as-loader/dist/runtime.

import * as assemblyModule from "./assembly/add.asc";
import { instantiateModule } from "as-loader/dist/runtime";


instantiateModule(assemblyModule).then(({ add, addMyObjs }) => {
  console.warn("add(1, 7) = " + add(1, 7));
});

Example repository

https://stackblitz.com/edit/webpack-webpack-js-org-waje4g

https://github.com/szacskesz/webpack-assemblyscript-loader-example

Example repository with angular

https://github.com/szacskesz/angular-assemblyscript-loader-example

License

MIT

Package Sidebar

Install

npm i @szacskesz/as-loader

Weekly Downloads

2

Version

0.27.6-RC-4

License

MIT

Unpacked Size

39.3 kB

Total Files

13

Last publish

Collaborators

  • szacskesz