作为标题,我目前所有 3 个部分都是单独完成的。我有一个 react 应用程序、node/express 服务器和一个包装 react 应用程序的电子。
我的目标是将 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");Run Code Online (Sandbox Code Playgroud)
我还在 build 文件夹中构建了 react 应用程序,当使用 nginx 服务器为其提供服务时,react build 很好。但是当我将 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, …Run Code Online (Sandbox Code Playgroud)