Menci / vite-plugin-wasm

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

import working in dev but not production #57

Open FUTC-Coding opened 4 months ago

FUTC-Coding commented 4 months ago

Hey there, I'm pretty new to wasm, and I don't know if this is an issue with vite-plugin-wasm or something to do with my setup, but this problem has been driving me crazy. In dev mode everything works perfectly fine, here is my vite.config.js:

import wasm from 'vite-plugin-wasm';
import topLevelAwait from 'vite-plugin-top-level-await';

export default {
    base: "/Halationify/",
    plugins: [
        wasm(),
        topLevelAwait()
    ],
    worker: {
        rollupOptions: {
            output: {
                format: "iife",
                inlineDynamicImports: true,
            }
        },
        plugins: () => {
            return [wasm(), topLevelAwait()]
        }
    },
};

I am using vite and runnning @silvia-odwyer/photon in a webworker to do some image processing. I simply import with const photon = await import('@silvia-odwyer/photon'); in the webworker.

Unfortunately, when building for production the import doesn't seem to work correctly and photon is undefined when the webworker executes, I think the wasm library isn't being bundled correctly. My project can be found here and the webworker where photon is imported can be found here. Thank you for making this plugin, and I hope somebody has a solution.

json91-dev commented 4 months ago

Me either .