How to bundle a worker in library mode? #15547
Unanswered
andreatiled
asked this question in
Q&A
Replies: 2 comments 1 reply
-
Does anyone know the answer to this? I am stuck at figuring out how can i deliver these assets as library to react app developers |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm working on an npm package that makes use of a web worker. The worker makes heavy use of imports and dynamic imports with wasms. So far the only option to make everything work is to inline the worker as so:
import MyWorker from './worker/worker_entrypoint?worker&inline'
But this unfortunately generates a huge bundle file (tens of MBs given that also the wasms are inlined) and essentially disables code splitting.
I've tried importing the worker differently such as:
?worker
: in the final bundle the worker ends up in/assets/worker-hash.js
resulting in 404 when a user uses the library?worker&url
: Same as before, usingnew URL(worker_as_url, import.meta.url)
makes no difference?url
: worker file gets simply encoded as base64 with wrong mime type and dependencies are not resolvednew Worker(new URL('./worker_entrypoint', import.meta.url), { type: 'module' })
: Similar problem as the first point but this time it ends up in/public/assets/worker-hash.js
Beta Was this translation helpful? Give feedback.
All reactions