V4+react: How do I add a web worker?

I can’t find any documentation on how to add a web worker to my Ionic V4 React project. Has anyone done this?

This would be very interesting to me, too.

Ionic+React is built on create-react-app. And as far as I can see, there are only a few hacky ways to get web workers integrated into create-react-app.

I think I’ve found a convenient way to set up a web worker, but with the huge limitation that it’s unable to access capacitor plugins.

The web worker code needs to be a self-contained .js file.
So I’ve set up a separate typescript project, with its own tsconfig.json.
This is bundled to assets/dist with parcel (use any bundler that you’re comfortable with).
Now I can start a webworker from my react app with:


const myWorker = new Worker("assets/dist/worker.js");