electron - 不能在带有 TypeScript Create React App 和预加载脚本的 Electron 中使用`require`
问题描述
我正在尝试ipcRenderer
在 (Create)React(app) 代码中导入 Electron,但遇到了障碍:
- 未执行预加载脚本:
new BrowserWindow({
titleBarStyle: "customButtonsOnHover",
resizable: false,
width: config.width,
height: config.height,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
preload: path.join(__dirname, "..", "preload.js"),
},
})
- 我尝试将脚本添加到 index.html
<script>
console.log(require);
</script>
这导致:
要求未定义
似乎是由于 webpack 路径无法正常工作?哪种解决方案适用于将电子 ipcRenderer 导入 React 代码?
解决方案
还需要为视图启用节点:
new BrowserView({
webPreferences: {
nodeIntegration: true,
},
})
推荐阅读
- postgresql - 使用第一列创建表,然后从另一个表中复制所有列
- python - 是否可以在 PyQt5 的循环中使用 lambda 函数将小部件作为参数传递?
- angular - Angular 导入的模块不等待 APP_INITIALIZER
- python - 为什么我无法安装 pyaudio?
- azure - 创建 DES 时参考 Azure Keyvault 版本
- php - 从 wp 帖子中获取以特定字母开头的标签 slug,然后在 qp_query 中使用它们
- r - Makefile / Makevars 在构建 R 包中的包含顺序和优先级
- ffmpeg - FFMPEG 中缺少 DirectShow 过滤器
- javascript - 使用 doc.data() 时如何将变量分配为字段名持有者。- Javascript Firebase Firestore
- android - 如何在 Flutter 中获取 GPS 时间?