-
-
Notifications
You must be signed in to change notification settings - Fork 995
Description
Before you start - checklist
- I understand that React-PDF does not aim to be a fully-fledged PDF viewer and is only a tool to make one
- I have checked if this feature request is not already reported
Description
The installation process for the web worker is a bit tedious and might be avoidable.
Proposed solution
I've got another project that utilizes a web worker. To avoid the issue around bundling and resolving the URL for the worker, I simply made it so that the worker is a string:
const workerCode = `...`;
const workerBlob = new Blob([workerCode], {
type: "application/javascript",
});
const workerUrl = URL.createObjectURL(workerBlob);
const worker = new Worker(workerUrl);This way you can have the worker code wherever you want, import it as you normally would but then avoid the consumer of the package having to "make sure it goes in the public folder" and have them resolve the path and stuff.
Another alternative that works with the node web-worker package is literally encoding the whole worker in the url:
const workerCode = `...`;
const worker = new Worker(`data:application/javascript,${encodeURIComponent(workerCode)}`)Could this be a possible option for this package as well? Or are there some issues that I have not foreseen yet? Maybe the size of your worker file could make this less ideal?
Alternatives
No response
Additional information
No response