comlink-loader
comlink-loader copied to clipboard
put worker scripts into index.html at build time
Hi there,
is there an option to put the generated scripts for the workers inside index.html at build time? we use publicPath="#CDN#" and this placeholder is replaced when the server parses the generated index.html with a cdn url that i cannot know at build time. So my config looks :
config.module .rule("comlink worker") .test(/\.worker\.js$/i) .use("comlink") .loader("comlink-loader") .options({ singleton: true, name:
staticV2/${buildNum}/js/[name].[hash:8].[ext]}) .end();
and it looks like this workers files are bundled in another script like so: return new Worker(r.p+"staticV2/TAG/js/formParser.worker.ea9dda30.js")}}
so this means that the server wont be able to replace that #CDN# placeholder and will result in an invalid path for this resource. e.g: #CDN#/staticV2/TAG/js/formParser.worker.ea9dda30.js'
I have tried to pass an option publicPath: ""
at least to try to load them from the actual server that makes the initial GET but no success.
Is there a solution you can suggest for my use case? Thanks
https://github.com/GoogleChromeLabs/worker-plugin/issues/36 this issue sums up exactly what i wanted to achieve with comlink-loader. I get the same error : Uncaught DOMException: Failed to construct 'Worker': Script at [cdndomain/scriptName] cannot be accessed from origin [url]