Is that possible with the modern JavaScript tools?
Is that possible with the modern JavaScript tools?
You also can't just compile any Javascript to WASM, the closest thing to this is AssemblyScript:
https://github.com/AssemblyScript/assemblyscript
This compiles a subset of Typescript to web assembly. And you have to take "subset" seriously here, web assembly is very limited in how memory is managed, you can't just drop your Javascript in there and get web assembly out.
If you want your process to run on the server, and merely pass the result to the client, you can compile JavaScript to C, and then to a binary, with QuickJs. Most folks will just use Nodejs, however (which also uses V8)
But it isn't a good idea. JS is a language that needs a runtime, the browser _has_ a JS engine, and not using that would just be counterproductive and wasteful.
I don't think that's the case anymore: https://dassur.ma/things/is-postmessage-slow/
Note that there is work to improve this (interface types, anyref, etc), but we're not there yet.