2017-02-21 171 views
1

我有一個應用程序,它具有單獨的ExpressJS後端和單獨的HTML前端。Electron JS,開始使用Express後端和單獨的html前端應用程序

我ExpressJS後端位於root/scripts/server.js

我的HTML前端位於root/index.html。這個前端使用了javascript邏輯,它是從webpack生成的,它工作正常。

爲了使這個項目的工作我第一次啓動我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後端?

+0

看看這一個[電子快遞(https://github.com/theallmightyjohnmanning/electron-express),並從那裏獲得靈感它。 – Redanium

回答

1

嘗試增加這樣的事情main.js:

const server = require('./scripts/server'); 
相關問題