Skip to content

How do I use bevy as wasm in frontend frameworks? #6031

Answered by afonsolage
wangxiaochuTHU asked this question in Q&A
Discussion options

You must be logged in to vote

It all depends on what you are trying to do JS wise. Bevy, when built targeting wasm32-unknown-unknown, is just a wasm module which needs some imports. wasm-bindgen generate those imports in the *.js or *.d.ts, depending if you want to use JS or TS.

With that being said, the trick part is on wasm-bindgen, since --target web will generate a self contained JS module, which is intended to be used as follow:

  <script type="module">
    import init from './a.js'
    init()
  </script>

That's it and init will handle all bootstrap needed by wasm module, which includes supplying the needed imports.

If you want to manual compile and instantiate the wasm module, you can tell the *.js file to expor…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@wangxiaochuTHU
Comment options

Comment options

You must be logged in to vote
2 replies
@bjorn3
Comment options

bjorn3 Sep 20, 2022
Collaborator

@wangxiaochuTHU
Comment options

Comment options

You must be logged in to vote
1 reply
@wangxiaochuTHU
Comment options

Answer selected by wangxiaochuTHU
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants