Wasm-bindgen: Does we need to use promise.then() to load wasm module as stated in the "Hello World" example

Created on 21 Apr 2020  路  4Comments  路  Source: rustwasm/wasm-bindgen

Summary

Hello, i just newly start learn webassembly with rust and take a look example on this example
https://rustwasm.github.io/docs/wasm-bindgen/examples/hello-world.html#indexjs

Does wasm-bindgen need to promise.then() first to load the wasm? but there is example using ECMAScript with code like this in introduction

import { greet } from "./hello_world";

greet("World!");
// Note that a dynamic `import` statement here is required due to
// webpack/webpack#6615, but in theory `import { greet } from './pkg';`
// will work here one day as well!

this paragraph make me confused how to do this so might need more explanation. are this import {greet} from './pkg'; already work for now or what

question

Most helpful comment

Using a dynamic import is required because Webpack doesn't currently support the synchronous version.

This was tracked by webpack/webpack#6615 and has been fixed in the next major version of Webpack - which will probably be released soon.

All 4 comments

Using a dynamic import is required because Webpack doesn't currently support the synchronous version.

This was tracked by webpack/webpack#6615 and has been fixed in the next major version of Webpack - which will probably be released soon.

Oh great! This is probably just code that needs to be updated!

i just start a new project just to showcase my project directory
[https://github.com/eisenhaus335/simple_showcase/(url)
i never test the wasm package so cant say for sure but please take alook at this https://github.com/eisenhaus335/simple_showcase/tree/master/src/pkg

the index.d.ts expose only inside wasm function. they not expose the promise first. its hard for me to explain but yeah is'nt that the index.d.ts need to give declaration for promise first and later give our important wasm func

after notice the difference between import {} from './pkg' and const wasm = import('./pkg') i think i know how to use wasm-bindgen. thanks for the support :D gotta close this issue

edit: ahh sorry i has not read the issue. i just realize everything. going to correct myself to read carefully next time

Was this page helpful?
0 / 5 - 0 ratings