我正在尝试构建 pdf.js 以便将查看器嵌入到我正在开发的应用程序中。
我想手动构建查看器,以便它可以包含在 webpack 打包的应用程序中。
应用程序入口点 index.js 有一行
import viewer from 'pdfjs-dist/web/pdf_viewer';
这导致查看器被包含在转译的应用程序代码中,但是 pdf.js 查看器使用 System.js 加载它需要运行的模块。
在 Mozilla 提供的编译版本中,代码已被转译为不使用 System.js;请参阅第 3774 行的 webViewerLoad 函数中的视图源:https ://mozilla.github.io/pdf.js/web/viewer.js。
function webViewerLoad() {
var config = getViewerConfiguration();
window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
pdfjsWebApp.PDFViewerApplication.run(config);
}
这与https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L178上的非转译源不同,Mozilla 托管查看器的源映射保留了这些SystemJS 行。
function webViewerLoad() {
let config = getViewerConfiguration();
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
Promise.all([
SystemJS.import('pdfjs-web/app'),
SystemJS.import('pdfjs-web/genericcom'),
SystemJS.import('pdfjs-web/pdf_print_service'),
]).then(function([app, ...otherModules]) {
window.PDFViewerApplication = app.PDFViewerApplication;
app.PDFViewerApplication.run(config);
});
} else {
window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
pdfjsWebApp.PDFViewerApplication.run(config);
}
}
我想知道这是如何实现的,以及如何复制配置来构建它。