Angular. Pdfjs-dist worker. Problem in deployed production enviroment

  Kiến thức lập trình

I need to use pdf library pdfjs-dist. I set up worker like this:

PDF.GlobalWorkerOptions.workerSrc = 'pdf.worker.mjs';

and in angular.json like this:

{
    "glob": "pdf.worker.*",
    "input": "node_modules/pdfjs-dist/legacy/build/",
    "output": ""
},
{
    "glob": "pdf.*",
    "input": "node_modules/pdfjs-dist/legacy/build/",
    "output": ""
}

The problem is that everything works locally but when the app is deployed setting up the worker fails and the file is blocked because of disallowed MIME „application/octet-stream”.

Update: I managed to get it working by copying the worker.min.js file into assets. And changing this:

PDF.GlobalWorkerOptions.workerSrc = '/assets/pdf.worker.mjs';

So I have another question. Is worker not included into bundle and that is why the problem is occuring? If so what is the appropriate solution.

How can I make it work without copying the worker file into assets folder?

1

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT