electron打包exe应用程序设置应用图标

electron打包exe应用程序设置应用图标

1、复制下面代码到package.json即可

{
  "name": "FoxChat",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "electron .",
    "build": "electron-builder -w --ia32 --dir"
  },
  "author": "caozj",
  "license": "ISC",
  "devDependencies": {
    "electron": "^16.0.1",
    "electron-builder": "^22.7.0"
  },
  "build": {
	"win": {
      "icon": "D:\\1\\ic.ico"
    }
  }
}

2、复制下面代码到main.js即可

{
  "name": "FoxChat",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "electron .",
    "build": "electron-builder -w --ia32 --dir"
  },
  "author": "caozj",
  "license": "ISC",
  "devDependencies": {
    "electron": "^16.0.1",
    "electron-builder": "^22.7.0"
  },
  "build": {
	"win": {
      "icon": "D:\\1\\ic.ico"
    }
  }
}
const { app, BrowserWindow } = require("electron");
const electron = require('electron')
/*获取electron窗体的菜单栏*/
const Menu = electron.Menu
/*隐藏electron创听的菜单栏*/
Menu.setApplicationMenu(null)
function createWindow() {
  // 创建浏览器窗口
  const win = new BrowserWindow({
    width: 1200,
    height: 800,
    webPreferences: {
      nodeIntegration: true,
    },
  });
  // 并且为你的应用加载index.html
  win.loadURL("你得url地址");
}

// Electron会在初始化完成并且准备好创建浏览器窗口时调用这个方法
// 部分 API 在 ready 事件触发后才能使用。
app.whenReady().then(createWindow);

//当所有窗口都被关闭后退出
app.on("window-all-closed", () => {
  // 在 macOS 上,除非用户用 Cmd + Q 确定地退出,
  // 否则绝大部分应用及其菜单栏会保持**。
  if (process.platform !== "darwin") {
    app.quit();
  }
});

app.on("activate", () => {
  // 在macOS上,当单击dock图标并且没有其他窗口打开时,
  // 通常在应用程序中重新创建一个窗口。
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});

你可能感兴趣的:(java,vue.js,html,javascript)