-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Support Webpack 4.0 #39
Comments
Oh nice! I've love to land support for this :) I gave this a spin locally and unfortunately it looks like this won't work out of the box yet as we're getting the error "Sync WebAssembly compilation is not yet implemented". The wasm-bindgen tool generates a JS file that looks like: // foo.js
import * as wasm from "./foo_wasm";
// ... and then it also emits a I'm not sure how to resolve this, but I'd imagine it's for sure fixable! Is there a way to require that the JS shim is itself asynchronously imported as well? We could probably hook in the wasm import promise into that in that case, but otherwise I'm not sure what the best way is to deal with the promise returned from the import of the wasm... |
in webpack 4.0 this shipping as experimental feature and turn off by default (or may turn very limit functionality). Are you try this? rules: [{
test: /\.wasm$/,
type: "webassembly/experimental"
}] |
@MaxGraey I think I tried that out yeah (although I'm also a newbie at webpack) but it didn't look to change the error message |
This is simple webpack config from this official example. Still not helped? PS I'm not sure import * as wasm from "./foo_wasm"; Support in beta. Try to rewrite this to: import * as wasm from "./foo_wasm.wasm"; And of course we don't need this: wasm2es6js js_hello_world_wasm.wasm -o js_hello_world_wasm.js --base64 |
@MaxGraey nah unfortunately the extension doesn't help, the problem here is that webpack I believe does not implement this functionality yet. This library currently assumes that Switching to using I've opened up webpack/webpack#6615 for synchronously importing wasm modules. |
what will be the problem here, It would be great to add in a loader in webpack to do this. taking inspiration from
What do you mean here, import it in the JS file and then use |
@sendilkumarn yeah ideally what I'm thinking of is something like: // at the top level
let wasm = await import('./foo_wasm'); sort of making it an "async module". This doesn't work today, however, and I'm not actually sure how it could work... |
w.r.t |
@sendilkumarn yeah I'm currently wonder what to generate in the |
but just an update (based on the discussion we had), you cannot use the sync import in the main chunk. But you can use it in other places. By this, if you have another JS file where you can use it via normal import syntax ( |
Aha awesome! To confirm @sendilkumarn (sorry I'm very much a JS newb) you mean this, right? // index.js
let foo = import('./foo.js');
// foo.js
import { foo } from './foo.wasm';
export const bar = foo; Because that does indeed work with webpack today! (yay!) To confirm though, this is expected to not work, right? // index.js
import { foo } from './foo.js';
// foo.js
import { foo } from './foo.wasm';
export const bar = foo; |
I think something like this: imports-from-wasm.js: import { foo } from './foo.wasm';
import { boo } from './boo.wasm';
// This place possible apply interop wrap/unwrap for foo and boo
export { foo, boo }; index.js: // async wrapper
void async function () {
const { foo, boo } = await import('./imports-from-wasm.js');
...
} (); |
// foo.js
import { foo } from './foo.wasm';
// call foo
foo() this will work, except that it should not be your chunk's main file. in other words ( In https://github.com/webpack/webpack/blob/master/test/cases/wasm/simple/module.js P.S. this is kinda super weird for me but this is how it works. |
Ok! Turns out no actual code changes were needed for this issue, but I've rewritten the intro example in the README to use Webpack as a bundler, so I'm going to close this. |
Thanks so much for the tip @sendilkumarn! |
@alexcrichton could you please share a link to this? We are having trouble getting this to work on webpack4. |
Since webpack 4.0 beta released we can implicitly import wasm files.
The text was updated successfully, but these errors were encountered: