From 37bc60ff633245230873859181da449a9dd4adb9 Mon Sep 17 00:00:00 2001 From: lniwn Date: Tue, 30 Jul 2019 17:46:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...用Electron+React开发跨平台桌面应用.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/content/posts/2019/使用Electron+React开发跨平台桌面应用.md b/content/posts/2019/使用Electron+React开发跨平台桌面应用.md index a2c4f15..402f5d0 100644 --- a/content/posts/2019/使用Electron+React开发跨平台桌面应用.md +++ b/content/posts/2019/使用Electron+React开发跨平台桌面应用.md @@ -53,7 +53,7 @@ const isDev = require('electron-is-dev'); let mainWindow; function createWindow() { - mainWindow = new BrowserWindow({width: 900, height: 680}); + mainWindow = new BrowserWindow({width: 900, height: 680, webPreferences: {nodeIntegration: true}}); mainWindow.loadURL(isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`); if (isDev) { // Open the DevTools. @@ -399,7 +399,19 @@ F:\Project\electron\web-designer-test ``` +## 开发笔记 +### 填坑记录 + +- 启动报错`'require()' is not defined.` + + 从Electron 5.0版本开始,`nodeIntegration`默认值由`true`改为`false`,具体可以参考[官方文档](https://github.com/electron/electron/blob/master/docs/api/breaking-changes.md#planned-breaking-api-changes-50),修改方式是在创建窗口时指定值为`true`即可。 + + ```javascript + mainWindow = new BrowserWindow({width: 900, height: 680, webPreferences: {nodeIntegration: true}}); + ``` + + *参考文档*