rustwasm / rust-webpack-template

Kickstart your Rust, WebAssembly, and Webpack project!
Apache License 2.0
562 stars 75 forks source link

Web Worker example #44

Open dakom opened 5 years ago

dakom commented 5 years ago

Would be helpful to have a web-worker example... I had lots of trouble getting that to load

xtuc commented 5 years ago

Would you mind sending a PR? What were your troubles?

dakom commented 5 years ago

Sure - I'm happy to fork/adapt to make a web-worker example.

Though when I tried with this repo, just as-is, I got:

error[E0277]: the trait bound `&mut syn::Field: quote::ToTokens` is not satisfied
   --> /Users/davidk/.cargo/registry/src/github.com-1ecc6299db9ec823/wasm-bindgen-macro-support-0.2.21/src/parser.rs:361:44
    |
361 |                 assert_not_variadic(&opts, &field)?;
    |                                            -^^^^^
    |                                            |
    |                                            the trait `quote::ToTokens` is not implemented for `&mut syn::Field`
    |                                            help: consider removing 1 leading `&`-references
    |
    = help: the following implementations were found:
              <syn::Field as quote::ToTokens>
    = note: required for the cast to the object type `dyn quote::ToTokens`
sendilkumarn commented 5 years ago

@dakom can you check this issue https://github.com/rustwasm/wasm-bindgen/issues/799 I think it is the same. Run cargo update

dakom commented 5 years ago

Yep, that fixed that error :)

dakom commented 5 years ago

Here you go - I put the changes in its own branch on the fork: https://github.com/dakom/rust-webpack-template/tree/worker-example

sendilkumarn commented 5 years ago

@dakom awesome, let me have a look 👍

dakom commented 5 years ago

Thanks! Related discussion fyi: https://github.com/webpack-contrib/worker-loader/issues/144

scottjmaddox commented 5 years ago

I'm running into the same error when trying to load a wasm-bindgen crate inside a web worker using webpack:

TypeError: Cannot read property '../client-wasm-worker/pkg/client_wasm_worker_bg.wasm' of undefined

This is only after using this workaround for a window is not defined error.

Any help would be greatly appreciated.

ashleygwilliams commented 5 years ago

https://github.com/VictorGavrish/rust-wasm-worker-template this is also a worker example!