I would like to use web workers in an ember project. However this web worker isn’t just going to be a single static Javascript file, I would like to be able to write it in Typescript and have the final worker JS bundle be build by ember build
and ember serve
. Is this possible?
1 Like
I did this easily by treating the entire webworker as a separate package. I was able to write native JS(TS), and not worry about any ember apis… I could even use ESBuild!
This project is quite out of date now (I don’t maintain it anymore), but you could use it as an example, perhaps
- here the line builds workers in the addon
- but that same function could be called from ember-cli-build.js if you don’t want a physical package separation.
The caveats: you can’t use @glimmer/tracking
or anything like that in a worker built this way.
You don’t really need to though, because you communicate with workers via postMessage / addEventListener
2 Likes