-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix: set Content-Type when serving .wasm files #13081
Conversation
|
I'm not sure if the change is at the right spot. The vite/packages/vite/src/node/plugins/asset.ts Lines 49 to 61 in 229c592
This should mutate |
Oh, that's strange... This plugin I wrote fixes the issue for me, FWIW: // vite.config.js
const wasmContentTypePlugin = {
name: "wasm-content-type-plugin",
configureServer(server) {
server.middlewares.use((req, res, next) => {
if (req.url.endsWith(".wasm")) {
res.setHeader("Content-Type", "application/wasm");
}
next();
});
},
};
export default defineConfig({
plugins: [wasmContentTypePlugin],
}); |
Could this be the right spot? |
Ah didn't see that mrmime already handled
I don't think so, those are additional headers added at sirv's final step, sirv handled the mime types early on at https://github.com/lukeed/sirv/blob/19c6895483cc71e9ef367f8a6a863af1e558ecb0/packages/sirv/index.js#L46. Maybe it's worth adding some loggings there to see what's wrong. |
@lynn I checked a reproduction: https://stackblitz.com/edit/vitejs-vite-rvb5zt?file=main.js,vite.config.js&terminal=dev Closing as Vite does respond with |
Description
I'm running into the same issue as mycelial/mycelial-js#25. It seems the vite dev-server doesn't serve .wasm files with the
application/wasm
Content-Type, soWebAssembly.instantiateStreaming
doesn't work.In mycelial/mycelial-js#25 (comment) the author suggests either patching over this or contributing a fix back to Vite, but I guess they ended up doing the former.
Additional context
I assume this change does the trick but I haven't tested it 😄 I'd like to add a test but I don't know how.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).