具体的可以看我的github:https://github.com/yedao-zs/electron-Packing.git
代码实现:
const { app, BrowserWindow,Menu } = require('electron');
const express = require('express');
const path = require('path');
const createWindow=()=>{
Menu.setApplicationMenu(null) // null值取消顶部菜单栏
// 创建窗口
let mainWindow=new BrowserWindow({
width: 1920,
height: 1080,
})
// 服务器端口
mainWindow.loadURL('http://localhost:3000');
//调试框
mainWindow.webContents.openDevTools();
// 释放内存
mainWindow.on('closed', function () {
mainWindow = null;
});
}
app.on('ready', () => {
const server = express();
// 将静态文件目录设置为打包后的资源路径
server.use(express.static(path.join(__dirname, 'dist')));
// 设置路由,返回 index.html 页面
server.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'dist', 'index.html'));
});
// 监听端口
server.listen(3000, () => {
console.log('Server running on port 3000');
createWindow();
});
});
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', function () {
if (mainWindow === null) {
createWindow();
}
});
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。