The Angular documentation says to do this:
ng generate web-worker location
And that works great. Just curious whether we have to generate the worker in a separate file or can we just create one a service:
const worker = new Worker()
worker.addEventListener('message', ({ data }) => {
const response = `worker response to ${data}`;
postMessage(response);
});
Thoughts?
It's not due to angular, it is due to Worker itself: yes, you are forced to use a separate file.
Hope this helps.