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

using wasm with Nuxt3 #19

Closed cesarecaoduro closed 1 year ago

cesarecaoduro commented 1 year ago

I am trying to use a wasm with Nuxt3 but it keeps failing...anyone that can help me with configuration?

nuxt.config.ts

import wasm from 'vite-plugin-wasm';

export default defineNuxtConfig({
    vite: {
        plugins: [
            wasm()
        ]
    }
})
Menci commented 1 year ago

Any reproduce?

cesarecaoduro commented 1 year ago

Hi @Menci, here you go... https://github.com/cesarecaoduro/nuxt-occ

Menci commented 1 year ago

Your WASM package is NOT one with esm-integration.

image

The opencascade.full.js is even not an ESM file. It's a handwriteen (or generated) WASM file loader. Following the declaration and guide, you shoud call init() to fetch and initialize the WASM module and it has nothing to do with this plugin. Maybe vite-plugin-top-level-await could help you since you need to await init().

Menci commented 1 year ago

Found a sample for you to use it with Vite. Note that you don't need this plugin.

https://github.com/donalffons/opencascade.js/pull/141/files#diff-881623410b5b8961b0a239ca26372de6ac76895634a7331256117145896fa250R52