我正在开发一个 PDF 查看器,基本上,它是一个mozilla pdf.js 项目。我克隆了 repo 并安装了依赖项,一切正常,即使我尝试通过 构建项目gulp generic
,它也可以正常工作。
问题开始时我已经安装electron
,创建查看器的桌面版本,即使在电子应用程序中一切仍然有效,但我习惯于const { ipcRenderer } = require('electron')
从浏览器窗口向主进程发送消息。在我尝试使用 构建应用程序之前,它也可以正常工作gulp generic
,它会显示一个错误Module not found: Error: Can't resolve 'fs' in '/*******/pdf.js/node_modules/electron'
。当我require('electron')
从脚本中删除它时,它会正确构建。
我的代码
function webViewerLoad() {
const isElectron =
navigator.userAgent.toLowerCase().indexOf(" electron/") > -1;
if (isElectron) {
const { ipcRenderer } = require("electron");
ipcRenderer.send("electron:reload", v);
}
}
document.addEventListener("DOMContentLoaded", webViewerLoad, true);
错误