-
Notifications
You must be signed in to change notification settings - Fork 17
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
SSR support #4
Comments
Just realized that |
Perhaps another approach might be to just try the fetch, then catch and see if it's an "ERR_INVALID_URL" error. If it is, we could try loading it from the file system. |
I don't use Vite SSR. But I see in Vite's docs there's an environment variable to tell if it's on server or client: https://vitejs.dev/guide/ssr.html#conditional-logic. Could you open a PR and send an example project for me(since I never used SSR)? Thanks. Additionally, this code is from Vite's builtin WASM plugin, you may also create a PR for that. |
Yeah, might be worth while to create a PR there as well. However, regarding the |
Could you please provide a simple WASM+SSR project, which works without SSR, for me to implement SSR support? |
Here's a simple example using SvelteKit. Just start the dev server and navigate to the SSR page. Everything works as expected if you apply the patch ( |
You have the directory |
It seems that |
I encountered the same issue when I tried to use |
I have created #16 with a patch that enabled me to get |
Just open sourced our vite wasm plugin with SSR support. It's only tested on our use case in our environment, so it probably has tons of gotchas and issues. Perhaps it could be used as inspiration if you choose to add SSR support. |
Added SSR support in |
I swapped out my hacky fork for Really appreciate your work on this plugin @Menci |
Currently the
wasmHelper
code tries to load the wasm file through fetch. This only works in a browser context. Even if fetch were available, fetching a relative path would still not work. I believe it should be fairly easy to get it working in a server context as well. One easy fix would be to add anelse if
clause in thewasmHelper
function:The
isServer
check could be as simple astypeof window === "undefined"
. However, I could see cases where this would be problematic. Some might have other vite plugins that polyfills window for server contexts etc. Another approach might be to use import.meta.url, and see if it refers to a URL or a file, e.g.import.meta.url.startsWith("file:")
. I'm not sure if this would always work, or if it might come with some gotchas.Are you open to a PR that implements something like this?
The text was updated successfully, but these errors were encountered: