From 820ef8e9103cf459f8a5385e508d6a8ace60ea86 Mon Sep 17 00:00:00 2001 From: Tushar <80577646+TusharThakur04@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:49:00 +0530 Subject: [PATCH] docs(guide): add information on the usage of publicPath in web workers --- src/content/guides/web-workers.mdx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/content/guides/web-workers.mdx b/src/content/guides/web-workers.mdx index 880175c02b0b..45ffdd34e636 100644 --- a/src/content/guides/web-workers.mdx +++ b/src/content/guides/web-workers.mdx @@ -105,8 +105,18 @@ const worker = new Worker(new URL("./worker.js", import.meta.url)); worker.postMessage({ publicPath: globalThis.__MY_GLOBAL_PUBLIC_PATH_VAR__ }); ``` +**When to use this:** + +This pattern is only required when a worker needs to load additional chunks and the asset base URL is determined at runtime (for example, when using a CDN or a multi-domain deployment). + +Since workers run in an isolated global scope, the automatically detected public path may differ from the one used by the main thread. In such cases, the public path (`__webpack_public_path__`) must be explicitly passed to the worker and set inside the worker runtime. + +> Note: This is an advanced use case. If your worker does not load additional chunks or your assets are served from a static, same-origin path, you typically do not need to set `__webpack_public_path__` manually. + ## Node.js +This section describes using Web Workers in a Node.js environment via the `worker_threads` module. + Similar syntax is supported in Node.js (>= 12.17.0): ```js