0.27.6-RC-4 • Published 10 months ago

@szacskesz/as-loader v0.27.6-RC-4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

0.27.6-RC-3

10 months ago

0.27.6-RC-2

10 months ago

0.27.6-RC-4

10 months ago

0.27.6-RC-1

10 months ago

0.27.1-FINAL

1 year ago

0.27.1

1 year ago

0.27.1-SNAPSHOT

1 year ago

0.13.0

1 year ago