File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -62,4 +62,21 @@ import { Worker } from 'worker_threads';
6262new Worker (new URL (' ./worker.js' , import .meta.url));
6363` ` `
6464
65- Note that this is only available in ESM. ` Worker ` in CommonJS syntax is not supported by either webpack or Node.js.
65+ ---
66+
67+ ## Advanced: Cross-Domain and Dynamic Web Workers
68+
69+ In some setups you might need your worker script to be hosted on a different origin
70+ (for example, using a CDN or micro-frontend).
71+ Webpack supports this, but you must make the worker aware of the correct public path.
72+
73+ ### Setting a dynamic public path
74+
75+ Inside the worker, explicitly set the same public path used by the main bundle:
76+
77+ ` ` ` js
78+ // worker.js
79+ /* global __webpack_public_path__, __webpack_require__ */
80+
81+ // Ensure the worker knows where to load chunks from
82+ __webpack_public_path__ = __webpack_require__ .p = self .location .origin + ' /assets/' ;
You can’t perform that action at this time.
0 commit comments