You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have to agree that in the majority of usecases returning the exports might be more convenient, but for people that need more control (in my case a custom wrapper around the exported methods), returning the instance object provides more options for customizations.
Suggested solution
Instead of return result.instance.exports using return result.instance
Alternative
What I have done so far is making a copy of packages/vite/src/node/plugins/wasm.ts, changing return result.instance.exports to return result.instance and registering a custom plugin via
which is - as far as I know - not exported and therefore not available to custom plugins.
In short, import { fileToUrl, Plugin, ResolvedConfig } from "vite"; in my custom WASM Plugin throws an error that the fileToUrl method is not exported. I again could make a copy of that method and all the methods it invokes ... but that's no fun at all.
hetsch
changed the title
Change WASM plugin to return the instance and not only the exports
Change WASM plugin to return the instance object and not only the exported methods
Nov 10, 2021
Clear and concise description of the problem
I'm currently using the WASM plugin and need to have access to the WASM instance object itself, not only to the exported methods.
vite/packages/vite/src/node/plugins/wasm.ts
Line 40 in a44f480
I have to agree that in the majority of usecases returning the exports might be more convenient, but for people that need more control (in my case a custom wrapper around the exported methods), returning the instance object provides more options for customizations.
Suggested solution
Instead of
return result.instance.exports
usingreturn result.instance
Alternative
What I have done so far is making a copy of
packages/vite/src/node/plugins/wasm.ts
, changingreturn result.instance.exports
toreturn result.instance
and registering a custom plugin viaThat has worked until lately. The original file uses the
fileToUrl
methodvite/packages/vite/src/node/plugins/wasm.ts
Line 3 in a44f480
vite/packages/vite/src/node/plugins/wasm.ts
Line 64 in a44f480
which is - as far as I know - not exported and therefore not available to custom plugins.
In short,
import { fileToUrl, Plugin, ResolvedConfig } from "vite";
in my custom WASM Plugin throws an error that thefileToUrl
method is not exported. I again could make a copy of that method and all the methods it invokes ... but that's no fun at all.Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: