Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support status for vite-plugin-wasm and testing env #24

Open
Jerboas86 opened this issue Jan 4, 2023 · 12 comments
Open

Support status for vite-plugin-wasm and testing env #24

Jerboas86 opened this issue Jan 4, 2023 · 12 comments

Comments

@Jerboas86
Copy link

Jerboas86 commented Jan 4, 2023

I was trying to uderstand where vite-plugin-wasm is supported.
The testing environment is here: https://github.com/Jerboas86/vpw-test-env

I tried different frameworks:

  • svelte (CSR)
  • sveltekit (SSR)

In different scopes:

  • Window scope
  • Worker scope
  • Worklet scope (audioworklet)
  • Nodejs scope (vitest)

And with different web browers:

  • Chrome 108
  • Firefox 108
  • Gnome web (aka Epiphany) 43

Results

Chrome

Svelte Sveltekit
Window
Worker
Worklet
Vitest

Firefox

Svelte Sveltekit
Window
Worker
Worklet
Vitest

Gnome web

Svelte Sveltekit
Window
Worker
Worklet
Vitest

opened issues:

and opened PR:

I would suggest to:

  • update the readme to reflect current support
  • and open issue for audioworklet support

The testing can also be extended if it is valuable, let me known.

@Jerboas86 Jerboas86 changed the title Support status for vite-wasm-plugin and testing env Support status for vite-plugin-wasm and testing env Jan 4, 2023
@Menci
Copy link
Owner

Menci commented Feb 5, 2023

image

Can't start your project

@Menci
Copy link
Owner

Menci commented Feb 5, 2023

I managed to build your project and added Vitest and SSR support. Please test~

@Menci
Copy link
Owner

Menci commented Feb 6, 2023

A question: what's the difference between Worker and Worklet. What extra steps will I need to make it work in Worklet?

@Jerboas86
Copy link
Author

With vite-plugin-wasm: v3.2.1

Results

Vitest

Svelte Sveltekit
Vitest

Chrome

Svelte Sveltekit
Window
Worker
Worklet

Firefox

Svelte Sveltekit
Window
Worker
Worklet

Gnome web

Svelte Sveltekit
Window
Worker
Worklet

@Jerboas86
Copy link
Author

A question: what's the difference between Worker and Worklet. What extra steps will I need to make it work in Worklet?

AFAIK, In AudioWorkletScope:

  • URL is not available.
  • fetch is not available.
  • import is not available (yet) in Firefox's worklet (see)

Other apis are not available (see)

I dont known if this is also true for others worklet: PainWorklet, LayoutWorklet, and AnimationWorklet.

@Menci
Copy link
Owner

Menci commented Feb 7, 2023

Does it mean I could only base64 encode the WASM file to load it in Worklet context? Are there any other APIs used by wasm-bindgen that is missing in Worklet context?

@Jerboas86
Copy link
Author

Does it mean I could only base64 encode the WASM file to load it in Worklet context?

I dont known

Are there any other APIs used by wasm-bindgen that is missing in Worklet context?

wasm-bindgen uses TextEncoder and TextDecoder (see).

@Menci
Copy link
Owner

Menci commented Feb 25, 2023

Firefox worker is supported now. Please test.

@Jerboas86
Copy link
Author

worker is still not working on FF, for both svelte and sveltekit (tested with with vite-plugin-wasm last commit)

this error message appears in the console.

SyntaxError: import declarations may only appear at top level of a module

@Menci
Copy link
Owner

Menci commented Feb 28, 2023

How did you build?

You need to set worker to iife, not es.

@Jerboas86
Copy link
Author

How did you build?

I retrieved the commit and built from source, maybe there is a better way?

package.json

{
  [...]
  "devDependencies": {
   [...]
    "vite-plugin-wasm": "[email protected]:Menci/vite-plugin-wasm.git#7ab4a5e"
  }
}

You need to set worker to iife, not es.

i used the default as specify in the README

vite.config.js

import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [svelte(), wasm(), topLevelAwait()],
  test: {
    environment: "jsdom",
  },
  worker: {
    plugins: [wasm(), topLevelAwait()],
  },
});

I push it on the repo, you can check it out, see if there is any mistake. (link)

@Menci
Copy link
Owner

Menci commented Feb 28, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants