【发布时间】:2020-04-05 06:12:59
【问题描述】:
作为标题,我目前所有 3 个部分都是单独完成的。我有一个反应应用程序、节点/快递服务器和一个电子包装反应应用程序。
我的目标是将 react 应用程序和节点服务器包装在 Electron 中。 react 应用程序在 localhost:3000 上运行,节点在 localhost:8080 上运行,所以我不确定 localhost 部分将如何工作。
我现在的工作是当我在 dev 中单独运行 react 应用程序和节点服务器,然后在电子中像这样打开 mainWindow,然后它就可以工作了。
mainWindow = new BrowserWindow({
width: 1100,
height: 1000,
webPreferences: {
nodeIntegration: true,
webSecurity: false
}
});
mainWindow.loadURL("localhost:3000");
我还在 build 文件夹中构建了 react 应用程序,当使用 nginx 服务器为其提供服务时,react 构建很好。但是当我将 startUrl 更改为此 index.html 显示一个空白屏幕。我还注意到,如果我在 chrome 中打开 index.html,它是相同的空白屏幕,因此它仅在有服务器提供服务时才有效。
const startUrl = url.format({
pathname: path.join(__dirname, '../build/index.html'),
protocol: 'file:',
slashes: true,
});
console.log(startUrl)
mainWindow = new BrowserWindow({
width: 1100,
height: 1000,
webPreferences: {
nodeIntegration: true,
webSecurity: false
}
});
mainWindow.loadURL(startUrl);
创建这个独立应用程序我应该做的任何一般指导或步骤,或者这是否可能?
【问题讨论】:
标签: node.js reactjs express build electron