chenhebing / assemblyscript-loader-loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

assemblyscript-loader-loader

Loader for webpack to compile typescript with AssemblyScript and bundle it to wasm or bytes string

Install

$ yarn add assemblyscript-loader-loader --dev

Usage

webpack.config.js

{
  test: /\.tsx?$/,
  loader: 'assemblyscript-loader-loader',
  include: /assemblyscript/,
  exclude: /node_modules/,
  options: {
    limit: 1000,
    optimize: true,
    noAssert: true,
    importMemory: true,
    runtime: 'none',
    useInWorker: true,
  }
}

file.js

import asmPromise from "./assemblyscript/test.ts";
const imports = { env: {}};
asmPromise(imports).then(function(asmModule){
  // you can use the wasm exports
})

Ths usage of imports can refer to @assemblyscript/loader

Options

The loader supports some of the assemblyscript options here

custom options

Name Type Default Description
limit string | number 1000 Byte limit of the wasm file. If the size is smaller then limit value, the wasm will bundled into js, or the wasm file will build into dist.
name string [name].[hash:7].wasm Configure a custom filename template for your file.
publicPath string __webpack_public_path__ Configure a custom public path for your file.
useInWorker boolean undefined If the wasm is used in web worker, you should set useInWorker to true. Loader will set publicPath to current origin. If production mode and development mode are different, you need set publicPath at production mode.

Thanks to the authors of assemblyscript-typescript-loader and assemblyscript-wasm-loader for their contributions.

About


Languages

Language:TypeScript 81.0%Language:JavaScript 19.0%