Use web workers with publicPath from runtime? #20039
-
|
I'm trying to figure out what is a correct way to use Web Workers with We use custom worker, that wrap whole worker to data url, to work around loading from CDN But webpack trying to load chunk from local host instead, Our custom worker is make Blob like this, to be passed to Worker later Adding publicPath override here seems do nothing, while both Should this publicPath override work in case of creating it via Blob, and loading it later via |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 20 replies
-
|
|
Beta Was this translation helpful? Give feedback.

@ogonkov Sorry for delay, I see your problem, there are some limitation:
DedicatedWorkerGlobalScope, so you should write__webpack_public_path__ = __PUBLIC_PATH__;line insrc/worker/worker.jsfilewindowinDedicatedWorkerGlobalScopeSo solution - after creating worker you need to call
worker.postMessage({ publicPath: __PUBLIC_PATH__ });, inside worker you need to handle itself.onmessage = async ({ data: { publicPath } }) => { if (publicPath) __webpack_public_path__ = publicPath /* other code of worker */ }), it will allow to override public path from window scope inside workerNote - above is pseudo code, y…