You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is the feature relevant to the Firefox PDF Viewer?
No
Feature description
It would be nice if the pdf.js package would define Package Exports in its package.json file. In essence, this allows to specify both which modules (or files) can be imported from a package depending on the runtime environment.
This would make it a lot easier to load pdf.js in a variety of situations, such as Node.js, webpack, or modern browsers, which right now all require different workarounds (like importing from the legacy/ folder, or setting the worker src, and so on).
Without further research, the exports for pdf.js might look like this:
With exports defined, the package as installed from npm would allow two exports:
import ... from 'pdfjs-dist';
import ... from 'pdfjs-dist/viewer';
The source file the above import statement resolves to depends on the runtime environment. This could be a lot more granular and I'm sure I made some wrong assumptions above, since I'm not very familiar with the code base.
I just wanted to bring this up as a possible ergonomics improvement here.
Other PDF viewers
No response
The text was updated successfully, but these errors were encountered:
The "problem" is that something like this would further increase the maintenance burden of the pdfjs-dist package, for a feature that's not needed in the Firefox PDF Viewer.
I would argue that it'd reduce the issue load from people who encounter import problems, but I certainly see your point. Feel free to close if this doesn't seem right.
In case a maintainer wants to pick this up, or someone is interested in getting it to work on their end: I created my own wrapper package with properly configured conditional package exports here:
It isn't published yet, but the code should be fairly straightforward to understand. Basically, there's separate exports for pdf.js, the viewer, and the sandbox; all of them support being imported from the browser or Node.js and will resolve to the correct module code automatically. When running in a browser, the worker source URL will also be set automatically at runtime.
So this reduces the code required to using pdf.js anywhere down to import pdf from '@your-ns/pdf'.
Is the feature relevant to the Firefox PDF Viewer?
No
Feature description
It would be nice if the pdf.js package would define Package Exports in its
package.json
file. In essence, this allows to specify both which modules (or files) can be imported from a package depending on the runtime environment.This would make it a lot easier to load pdf.js in a variety of situations, such as Node.js, webpack, or modern browsers, which right now all require different workarounds (like importing from the
legacy/
folder, or setting the worker src, and so on).Without further research, the exports for pdf.js might look like this:
With exports defined, the package as installed from npm would allow two exports:
import ... from 'pdfjs-dist';
import ... from 'pdfjs-dist/viewer';
The source file the above import statement resolves to depends on the runtime environment. This could be a lot more granular and I'm sure I made some wrong assumptions above, since I'm not very familiar with the code base.
I just wanted to bring this up as a possible ergonomics improvement here.
Other PDF viewers
No response
The text was updated successfully, but these errors were encountered: