I’m trying to load a the starter Purescript app in the emscriptem generated module callback. Although my problem is specific to this setup, I think it can be generalised to being able to run Purescript main after a callback. Emscriptem calls a Module.onRuntimeInitialized () if defined once it has loaded WASM and done all its setup.
(older version of parcel here - you’ll need the type=module stuff)
This is for development, where I’ll use the compiled purescript modules (it works a bit like Hot-Module-Reloading this way … well minus the persisted model)
For production I’ll compile the purescript using spago bundle-app (I had not big success with further tree-shaking/minification so I usually don’t bother) and change the index.js to
import { main } from '../dce-output/Main'
main()
(or something similar)
in your case you’ll need your wait/continuation so I’d try adding this to the index.js or reference ../output/Main from your index.html and try there - no matter what usually you start your app by calling main()
import { main } from '../output/Main';
import Module from '../assets/output';
let instance = Module({
onRuntimeInitialized() {
console.log("hello");
main();
}
});
And it worked. Parcelv2 even copied the output.wasm to the correct location which it wasn’t doing before. I’ll need to see if I can get a spago build-module version working.