1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

[api-minor] Attempt to improve support for using the PDF.js builds with Vite

Similar to Webpack there's apparently other bundlers that will not leave `import`-calls alone unless magic comments are used.
Hence we extend the builder to also append `/* @vite-ignore */` comments to `import`-calls, in order to attempt to improve support for using the PDF.js builds together with Vite.

This patch also renames `__non_webpack_import__` to `__raw_import__` since the functionality is no longer bundler-specific.

***PLEASE NOTE:*** This patch is provided as-is, and it does *not* mean that the PDF.js project can/will provide official support for Vite.
This commit is contained in:
Jonas Jenwald 2025-03-27 21:31:27 +01:00
parent 34136d7775
commit 8bcc3664c9
8 changed files with 19 additions and 12 deletions

View file

@ -57,7 +57,7 @@ class JpxImage {
try {
const mod = await (typeof PDFJSDev === "undefined"
? import(path) // eslint-disable-line no-unsanitized/method
: __non_webpack_import__(path));
: __raw_import__(path));
instance = mod.default();
} catch (e) {
warn(`JpxImage#getJsModule: ${e}`);

View file

@ -2416,7 +2416,7 @@ class PDFWorker {
const worker =
typeof PDFJSDev === "undefined"
? await import("pdfjs/pdf.worker.js")
: await __non_webpack_import__(this.workerSrc);
: await __raw_import__(this.workerSrc);
return worker.WorkerMessageHandler;
};