Open
Description
Motivation
Especially after #1843, I think it would make a lot of sense that on importing the js
file, it would immediately start init
and therefore execute main
.
This would solve a couple of issues:
- Less boilerplate:
<script src="wasm.js" type="module"></script>
would be enough.- No need to call
init
. - No need to preload the
js
file (thewasm
still needs to be preloaded).
- No need to call
- Can be directly used with
Worker
, because it starts itself. - It should only start itself when
main
orwasm_bindgen(start)
is used in rust, which should be pretty intuitive. - Behaving like other output modes,
bundler
andnodejs
already do that.
Proposed Solution
Call init
after its definition if needs_manual_start
is true in cli-support
.
Additionally we should add a flag to disable this functionality.
Alternatives
- Potentially we could always call
init
to start loading thewasm
file, even if there is no start function. - Hide this functionality behind a flag instead of making it default and disabling it by a flag.
Additional Context
I am afraid there was some reason that this functionality wasn't implemented already, I just can't figure out why.
EDIT: Just started to implement this when I found the other output modes already do that, only no-modules
and web
don't.