ceifa / wasmoon

A real lua 5.4 VM with JS bindings made with webassembly
MIT License
449 stars 29 forks source link

Ability to be used offline #76

Closed TechStudent10 closed 1 year ago

TechStudent10 commented 1 year ago

I'm building an Electron app that utilizes Wasmoon. When I went off the grid and attempt to use my app, I see that wasmoon fetches a file called glue.wasm. Is there anyway for me to download this file and provide it to wasmoon.

Thanks.

image

ceifa commented 1 year ago

There is no need to be online to use wasmoon. You can use the local copy of the wasm file if you want. Example of this using webpack: https://github.com/Drumsin/aoe4-generated-map-debugger/pull/6

TechStudent10 commented 1 year ago

There is no need to be online to use wasmoon. You can use the local copy of the wasm file if you want. Example of this using webpack: Drumsin/aoe4-generated-map-debugger#6

Thank you!

TechStudent10 commented 1 year ago

Apparently you cannot use this import statement in TypeScript...

image

TechStudent10 commented 1 year ago

@ceifa should note that I'm not using webpack, but rather Vite.

TechStudent10 commented 1 year ago

@ceifa please get back to me. Once again, I'm using Vite (TypeScript) and I've moved to Tauri. When building it, the app fails to fetch because glue.wasm is being served over http. I can't build my application without removing wasmoon.

ceifa commented 1 year ago

This will be fixed on the next release, for now you can just pass the url as parameter to the factory:

new LuaFactory("https://unpkg.com/wasmoon/dist/glue.wasm")
TechStudent10 commented 1 year ago

This will be fixed on the next release, for now you can just pass the url as parameter to the factory:

new LuaFactory("https://unpkg.com/wasmoon/dist/glue.wasm")

You misunderstood me. While this is a temporary fix, I want to be able to serve it offline.

TechStudent10 commented 1 year ago

Finally found a fix. If you are using Vite, you need to copy the glue.wasm file from node_modules/wasmoon/dist/ to your assets/public folder. Then, you can instantiate LuaFactory like so:

new LuaFactory("/glue.wasm")
gsw945 commented 6 months ago

below is working for me:

import wasmoonGlueUrl from "wasmoon/dist/glue.wasm?url"

const factory = new LuaFactory(wasmoonGlueUrl)

ref:

pureliumy commented 1 month ago

Hi @ceifa , I have the similar problem with Vercel, here is the error log.

RuntimeError: Aborted(Error: ENOENT: no such file or directory, open 'https:/unpkg.com/wasmoon/dist/glue.wasm'). Build with -sASSERTIONS for more info.
    at C (/var/task/node_modules/.pnpm/wasmoon@1.15.0/node_modules/wasmoon/dist/index.js:1181:328)
    at Fa (/var/task/node_modules/.pnpm/wasmoon@1.15.0/node_modules/wasmoon/dist/index.js:1182:635)
    at /var/task/node_modules/.pnpm/wasmoon@1.15.0/node_modules/wasmoon/dist/index.js:1183:399
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)