@stagas/vite-plugin-assemblyscript
v1.0.0
Published
Use AssemblyScript in Vite projects.
Readme
@stagas/vite-plugin-assemblyscript
Use AssemblyScript in Vite projects.
This plugin runs the AssemblyScript compiler when Vite starts, switches between debug and release AssemblyScript targets based on the Vite mode, and recompiles AssemblyScript sources during development with Vite hot updates.
Install
npm install @stagas/vite-plugin-assemblyscript assemblyscriptAssemblyScript is also installed by this package, but keeping it in your app's dependencies makes your compiler version explicit.
Usage
Add the plugin to your Vite config:
import { defineConfig } from 'vite'
import { assemblyScript } from '@stagas/vite-plugin-assemblyscript'
export default defineConfig({
plugins: [
assemblyScript(),
],
})By default, the plugin expects this project layout:
assembly/index.ts
asconfig.json
build/index.wasm
build/index.wasm.mapYour asconfig.json should define debug and release targets. For example:
{
"targets": {
"debug": {
"outFile": "build/index.wasm",
"sourceMap": true,
"debug": true
},
"release": {
"outFile": "build/index.wasm",
"sourceMap": true,
"optimizeLevel": 3,
"shrinkLevel": 0
}
}
}Then import the generated wasm from your app however you normally load wasm in Vite:
import wasmUrl from './build/index.wasm?url'
const bytes = await fetch(wasmUrl).then((res) => res.arrayBuffer())
const module = await WebAssembly.instantiate(bytes)Options
assemblyScript({
projectRoot: '.',
sourceRoot: '/',
configFile: 'asconfig.json',
srcMatch: 'assembly',
srcEntryFile: 'assembly/index.ts',
mapFile: './build/index.wasm.map',
extra: [],
})| Option | Default | Description |
| --- | --- | --- |
| projectRoot | . | Root used to resolve AssemblyScript input and output paths. |
| sourceRoot | / | Source map root written into the generated wasm source map. |
| configFile | asconfig.json | AssemblyScript config file passed to asc --config. |
| srcMatch | assembly | Directory watched for hot updates. |
| srcEntryFile | assembly/index.ts | AssemblyScript entry file passed to asc. |
| mapFile | ./build/index.wasm.map | Source map generated by AssemblyScript and patched by the plugin. |
| extra | [] | Extra arguments passed to the AssemblyScript compiler. |
License
MIT
