第一步:安装node.js npm,不会自己查
第二步: 创建Electron目录
npx create-electron-app work
第三步:修改 work/src/index.js 目的为了禁止使用开发者
const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
},
webPreferences:{
//禁止打开开发者
devTools:false
},
});
// and load the index.html of the app.
//mainWindow.loadFile(path.join(__dirname, 'index.html'));
// Open the DevTools.
// 关闭打开开发者
//mainWindow.webContents.openDevTools();
};
第四步:修改自定义菜单
//增加 Menu
const { app, BrowserWindow, Menu } = require('electron');
//菜单模板
const customMenuTemplate = [
{
label: '菜单',
submenu: [
{
label: '刷新',
role: 'reload', // 使用内置角色以实现刷新功能
},
],
},
];
//加载
const customMenu = Menu.buildFromTemplate(customMenuTemplate);
const createWindow = () => {
//然后set就行了
Menu.setApplicationMenu(customMenu);
}
第五步:运行 npm start 没啥问题就能打包了
第六步:安装 npm install electron-builder
第七步:打包 npm run make