PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.59k stars 369 forks source link

[RFC] Bundling WASM modules #510

Open GarciaLnk opened 1 year ago

GarciaLnk commented 1 year ago

How do you envision this feature/change to look/work like?

Plasmo should allow importing WASM modules following the WASM ESM spec: import {a,b,c} from "./x.wasm"

What is the purpose of this change/feature? Why?

Currently, Plasmo relies on Parcel v2 to bundle WASM modules, which are not properly supported yet (see https://github.com/parcel-bundler/parcel/issues/1325).

Trying to import an x.wasm library returns the error No transformers found for x.wasm.

Ideally, Plasmo's Parcel implementation would be modified to allow bundling WASM modules (like Webpack).

(OPTIONAL) Example implementations

No response

(OPTIONAL) Contact Details

No response

Verify canary release

Code of Conduct

louisgv commented 1 year ago

@GarciaLnk Thanks for filing this issue! Here's an example of using WASM in Plasmo: https://github.com/PlasmoHQ/with-wasm-zig

Can you elaborate a bit on "WASM ESM spec."

Ref: #102

GarciaLnk commented 1 year ago

I'm aware of that example, however WASM libraries are moving towards a model where WASM modules are treated as ES modules as defined in this WebAssembly's proposal (this is what I mean by WASM ESM spec): https://github.com/WebAssembly/esm-integration/tree/main/proposals/esm-integration

That means that if I want to use a WASM library from the npm registry, I won't be able to do so if they follow this model, which is now the default of tools like wasm-pack.

I also want to note that this was even supported (at least partially) in Parcel v1

t123yh commented 1 year ago

Support for importing wasm will enable the usage of packages like https://www.npmjs.com/package/lz4-wasm , which would be quite useful.