Have an alias (e.g. PDFJS or PDFJS2) instead of window['pdfjs-dist/build/pdf'] or window.pdfjsDistBuildPdf
See original GitHub issue#9493 removed the PDFJS
global, so now the only way to access the PDF.js library from a browser in a non-module context (i.e. not AMD or CommonJS) is through window['pdfjs-dist/build/pdf']
or window.pdfjsDistBuildPdf
.
This is an unfriendly name, and seemingly just an artefact of the implementation. Can we use a global such as PDFJS
, or if you wish, PDFJS2
?
The name originates from here: https://github.com/mozilla/pdf.js/blob/6662985a20b769d7e78e7cf4486eb6b7130f0cf0/gulpfile.js#L228-L235 https://github.com/mozilla/pdf.js/blob/6662985a20b769d7e78e7cf4486eb6b7130f0cf0/gulpfile.js#L241-L253
The window['pdfjs-dist/build/pdf']
export is done by Webpack, and can probably be configured by replacing the library
string with an object, and set root
to the desired name.
The window.pdfjsDistBuildPdf
export is generated by our custom replaceJSRootName
function. An alternative to reconfiguring Webpack is to add an extra parameter to the replaceJSRootName
function, so that the caller defines jsName
instead of auto-generating it.
I would personally be in favor of configuring Webpack to use the custom name, because I cannot imagine anyone wanting to use window['pdfjs-dist/build/pdf']
to import the JS variable.
Relevant Webpack documentation for configuring the library
:
- https://webpack.js.org/configuration/output/#output-library (The documentation does not have any explicit information for configuring the UMD target, so I digged in the source and found the following)
- https://github.com/webpack/webpack/blob/41bb63ad69d0f32c042e74e732cb045b5966c452/schemas/WebpackOptions.json#L484-L516 - the schema that the configuration needs to adhere to.
- https://github.com/webpack/webpack/blob/41bb63ad69d0f32c042e74e732cb045b5966c452/test/configCases/library/umd/webpack.config.js (example)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top GitHub Comments
I missed that we have three export like things now. In light of that, I’m in favor of Jonas’ suggestions of pdfjsLib, pdfjsViewer, pdfjsWorker.
I’m leaning towards keeping PDFJS and letting the version number be the indication of change. If we change the name this time it seems like we should change it every major release, which I’d rather not do.