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

Question: how to specify the wasm path in the generated js file? #131

Open
slmjkdbtl opened this issue Aug 19, 2018 · 3 comments
Open

Question: how to specify the wasm path in the generated js file? #131

slmjkdbtl opened this issue Aug 19, 2018 · 3 comments

Comments

@slmjkdbtl
Copy link

slmjkdbtl commented Aug 19, 2018

In the generated js file there's

return fetch( "main.wasm", {credentials: "same-origin"} )

is there a way to customize the wasm path (like "wasm/main.wasm")?

also is there a way to remove the

console.log( "Finished loading Rust wasm module 'main'" );

part (or like omit it in like production mode)?

@koute
Copy link
Owner

koute commented Aug 19, 2018

Currently this is not customizable, however you can use --runtime=library-es6 argument to generate a .js file which you can load manually yourself. (It exports two things - imports and initialize. You need to load the WASM module yourself and pass the imports when instantiating it, and then use initialize on the instantiated module.)

@Pauan
Copy link
Contributor

Pauan commented Aug 20, 2018

@slmjkdbtl To be more specific, you would do something like this:

import init from "./path/to/js";

const wasm = init();

WebAssembly.instantiateStreaming(fetch("path/to/wasm"), wasm.imports).then((result) => {
    const exports = wasm.initialize(result.instance);
});

@slmjkdbtl
Copy link
Author

@koute @Pauan Thank you, very helpful! But will there be an option to specify such thing in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants