Menci / vite-plugin-wasm

Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
MIT License
281 stars 16 forks source link

Firefox web workers #18

Closed segevfiner closed 1 year ago

segevfiner commented 1 year ago

AFAIK Firefox doesn't support ESM in workers ATM so setting workers.format to es will break the resulting sure in Firefox. I think Vite explicitly has code to transform workers in dev mode rather than rely on ESM so they will work in Firefox. Any way to get this plugin to work with classic workers?

Menci commented 1 year ago

Rollup only accepts code with TLA in ES mode, not in IIFE mode. So I'm going to add some magic hack in my plugin (vite-plugin-top-level-await) to make the worker code build as ES first and then transform the built code to IIFE to make it work in Firefox.

segevfiner commented 1 year ago

BTW, Firefox might be going to add ESM workers in v110

Menci commented 1 year ago

Supported with vite-plugin-top-level-await v1.3.0.