-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External worker dependency (for Next.js) #30
Comments
@dmudro |
@phuoc-ng sounds good in theory but if you follow your guide, there are some Next.js specificities probably not compatible with the suggested solution for "pure webpack". Namely this part of the custom webpack config:
What's the Next.js equivalent? Even if this worked:
... where is the "worker bundle" accessible from? Obviously Basically all we need to to do is to be able to access the
My concern is if it is right to write into |
if your nextjs app already uses webpack v5, you can simply do this: (no extra configuration needed) const workerUrl = new URL('../node_modules/pdfjs-dist/build/pdf.worker.js', import.meta.url).toString();
<Worker workerUrl={workerUrl}></Worker> |
Cheers @raibima, I tried asset modules as suggested with some tweaks around
Next.js 11 So it should work... However, the local dev server does not serve files off the root of the build dir, gives 404 back. I reckon it would need to be inside Now even if it all worked, I am not quite sure if using Next.js 12 Given asset modules do not seem to be production ready in Next.js 12 yet, the right strategy seems to be waiting for how that experimental feature pans out and then reconsider. Until then I will most likely go with my CopyPlugin solution which works with v12. Perhaps copying assets on my own into .next buil dir is not too bad. @phuoc-ng you might want to reflect the new versions of Webpack and Next.js in your starter guide |
not sure why it doesn't work for you in dev but I use it in dev + prod just fine using the snippet I shared previously (nextjs 12). In my case, it'll be served under:
So nextjs automatically does the copying / "bundling" from node_modules/pdfjs-dist to |
Alright. I'll revisit to make sure I didnt have something locally conflicting with asset modues and will report back here if I find out anything. |
The Next.js starter suggest an external dependency on the pdf worker:
Since we already have the worker file in
node_modules/pdfjs-dist
it would be more feasible to use the local file and avoid the external http call and to improve the integrity of pdfjs-dist version in the first place.Any ideas what's the best approach here?
I appreciate this might not be directly related to the pdf viewer code base as such. Perhaps a separate webpack bundle with the worker could do the job here.
The text was updated successfully, but these errors were encountered: