Skip to content

Commit 512004e

Browse files
author
Je
committed
chore: add plugin(wasm) example
1 parent 0f3d085 commit 512004e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

examples/wasm-plugin/aleph.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { } from "https://deno.land/[email protected]/encoding/base64.ts"
2+
3+
export default {
4+
plugins: [{
5+
test: /.wasm$/,
6+
transform(content: Uint8Array) {
7+
return {
8+
code: `
9+
const wasmCode = new Uint8Array([${content.join(',')}])
10+
const wasmModule = new WebAssembly.Module(wasmCode)
11+
const wasmInstance = new WebAssembly.Instance(wasmModule)
12+
export default wasmInstance.exports
13+
`,
14+
loader: 'js'
15+
}
16+
}
17+
}]
18+
}

examples/wasm-plugin/pages/42.wasm

92 Bytes
Binary file not shown.

examples/wasm-plugin/pages/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'https://esm.sh/react'
2+
import wasm from './42.wasm'
3+
4+
export default function Home() {
5+
return (
6+
<h1>{wasm.main()}</h1>
7+
)
8+
}

0 commit comments

Comments
 (0)