Home > Enterprise >  set runtime public path for webworker chunkloading stub
set runtime public path for webworker chunkloading stub

Time:12-15

I have a webpack library which contains a webworker (imported via the 'magic' worker handler) and I am trying to run this library from another project (in this instance an angular project).

I have correctly copied the worker (and worker chunk) files to the output of my angular project as the webworker will correctly run if I run my angular project in the same domain it is hosted from.

this is the code used to run the worker (and in turn add it to webpack)

var worker = new Worker(new URL('../worker/worker.ts', import.meta.url));

and I have replaced the default worker with a stub that handles cross domain failover.

My issue is that my project normally does not run same domain context and instead runs on separate domains. I can set the __webpack_public_path__ in the non-worker code such that the web worker url is correctly resolved - however the webworker just loads a chunk-loading stub which has the embedded public path (if set) from the webpack config, but no means of altering it at runtime.

My question is - is there a way I can edit that chunkloading stub to have a different public path at runtime, or, is there a way to alter how the library interacts with the webpacker of the angular project such that the value used for deploypath there is copied to the worker js libraries being copied (via the additional assets in angular.json)?

CodePudding user response:

having looked through code and such it doesn't appear there is a built in way to do this. I ended up making a plugin based on https://github.com/agoldis/webpack-require-from in order to work for my specific case

  • Related