Menci / vite-plugin-wasm

Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
MIT License
276 stars 16 forks source link

Plugin always bundles Wasm as base64 when vitest is installed #46

Open willcrichton opened 8 months ago

willcrichton commented 8 months ago

I have a Vite app, and I have Vitest installed. When I run vite build, my Wasm file is bundled as base64, even though I want it to be bundled as a URL. This line of code seems to be the problem:

https://github.com/Menci/vite-plugin-wasm/blob/f9718b9df29822010c81c0630f2cadce9fafc6fe/src/index.ts#L16

I guess the config plugins includes vitest even when I'm not using it?

Menci commented 8 months ago

Oh... So how can I detect if it's actually running in Vitest environment?

willcrichton commented 8 months ago

I don't know, sorry. Otherwise I would propose a fix :')

jbordenHighRezConsulting commented 5 months ago

I am having the same issue as @willcrichton and decided to do some more digging and believe that this is not the issue. You can run vite build --debug and it will print out the config with the list of plugins it is using and is the same array of values used in the line @willcrichton shows in the original post.

Not sure what the issue is, but my .wasm file made using wasm-pack --target web is also being inlined as a base64 string and I can't figure out what in Vite is doing it. It happens even without this plugin.