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

Change WASM plugin to return the instance object and not only the exported methods #5615

Closed
4 tasks done
hetsch opened this issue Nov 10, 2021 · 0 comments · Fixed by #8219
Closed
4 tasks done

Change WASM plugin to return the instance object and not only the exported methods #5615

hetsch opened this issue Nov 10, 2021 · 0 comments · Fixed by #8219

Comments

@hetsch
Copy link

hetsch commented 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.

return result.instance.exports

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

plugins: [
  vue(),
  {
    ...customWASMPlugin(),
    enforce: "pre",
  },
],

That has worked until lately. The original file uses the fileToUrl method

import { fileToUrl } from './asset'

const url = await fileToUrl(id, config, this)

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.

Additional context

No response

Validations

@hetsch 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
@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants