-
-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathplugin.ts
More file actions
28 lines (26 loc) · 855 Bytes
/
plugin.ts
File metadata and controls
28 lines (26 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { plugin } from 'bun'
plugin({
name: 'wasm-pack-bun-loader',
setup(build) {
build.onLoad({ filter: /_bg\.wasm$/ }, async ({ path }) => {
const jsPath = `${path.slice(0, -5)}.js`
const glue = await import(jsPath)
const bytes = await Bun.file(path).arrayBuffer()
const instantiated = await WebAssembly.instantiate(bytes, {
'./index_bg.js': {
__wbindgen_cast_0000000000000001:
glue.__wbindgen_cast_0000000000000001,
__wbindgen_init_externref_table: glue.__wbindgen_init_externref_table,
},
})
const instance =
instantiated instanceof WebAssembly.Instance
? instantiated
: instantiated.instance
return {
exports: Object.fromEntries(Object.entries(instance.exports)),
loader: 'object',
}
})
},
})