Electron JS,使用Express后端和单独的html前端启动应用程序
我有一个单独的ExpressJS后端和单独的HTML前端的应用程序。
我的ExpressJS后端位于root/scripts/server.js
我的HTML正面位于root/index.html
。 这个前面使用了从webpack
生成的javascript逻辑,它工作正常。
为了使这个项目工作,我首先用这个命令启动我的ExpressJS后端:
babel-node ./scripts/server.js --presets es2015,stage-0
然后我打开我的index.html
,一切正常。
现在我想通过使用ElectronJS在一个桌面应用程序中打包后端和前端。
我的项目有以桌面模式启动电子应用程序的main.js
脚本。 它位于root/main.js
。 它有以下代码:
const electron = require('electron') const app = electron.app const BrowserWindow = electron.BrowserWindow const path = require('path') const url = require('url') let mainWindow function createWindow () { mainWindow = new BrowserWindow({ width: 800, height: 600, autoHideMenuBar: true, useContentSize: true, resizable: false }) mainWindow.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true })) mainWindow.webContents.openDevTools() mainWindow.on('closed', function () { mainWindow = null }) } app.on('ready', createWindow) app.on('window-all-closed', function () { if (process.platform !== 'darwin') { app.quit() } }) app.on('activate', function () { if (mainWindow === null) { createWindow() } })
这个脚本只启动我的HTML前台 。 我需要添加什么,以便用HTML前端打包Express后端?
尝试添加像这样main.js:
const server = require('./scripts/server');