I want to bundle a WebWorker script using Webpack 5. The way to do this given the current documentation is:
const worker = new Worker('./path_to_worker.js', import.meta.url)
However I want to start the worker in a different context of where I defined it. I want to get the url string for the worker and actually start it elsewhere.
const workerUrl = ... get webpack bundled path to worker...
... somewhere else in the code ...
let worker = new Worker(workerUrl)
Dynamic imports could generate the bundle for the Worker, but I am unable to get the url of the imported script so I can pass it to the worker constructor at later moment in the program execution.
How would I be able to do this?