Skip to content
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

More instructions on worker loading with create-react-app (cra) #685

Closed
moritzmhmk opened this issue Nov 20, 2020 · 1 comment · Fixed by #756
Closed

More instructions on worker loading with create-react-app (cra) #685

moritzmhmk opened this issue Nov 20, 2020 · 1 comment · Fixed by #756

Comments

@moritzmhmk
Copy link

Is your feature request related to a problem? Please describe.

Instructions on setting pdfjs.GlobalWorkerOptions.workerSrc when using create-react-app (CRA) are rather sparse.

Describe the solution you'd like

I have managed to get around manually copying the files or loading from a CDN (which is not an option for every project) and would like to suggest adding further instructions to the README ;)

Additional information

I use the file-loader via webpack-loader-syntax which is an anti-pattern in CRA because it is not packer agnostic and might break in the future, BUT in the future loading web workers hopefully also works ootb rendering this obsolete...

/* eslint-disable-next-line import/no-webpack-loader-syntax */
import worker from "file-loader!pdfjs-dist/build/pdf.worker.js";
pdfjs.GlobalWorkerOptions.workerSrc = worker;

For typescript support also add this to react-app-env.d.ts

declare module "file-loader!*" {
  const content: string;
  export default content;
}
@wojtekmaj
Copy link
Owner

Please kindly check React-PDF v5.3.0-beta.2, in which improvements regarding loading PDF.js worker were made.

With these changes you should be able to use Webpack entry file in Create-React-App, without the need of using external CDN for hosting worker.

Let me know what you think in #748!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants