You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Ubuntu 22.04环境下用Electron-Forge打包Windows应用?

在Ubuntu 22.04下打包Electron Windows应用的解决方案

核心结论

不需要必须使用Windows环境,在Ubuntu 22.04下可以通过安装Wine来生成Windows版本的打包应用。你当前未得到Windows相关输出,是因为@electron-forge/maker-squirrel默认依赖Windows环境,Linux下需要Wine模拟才能正常触发该打包流程。

具体操作步骤

  1. 安装Wine环境
    在Ubuntu 22.04中安装Wine稳定版,用于模拟Windows运行环境:
sudo dpkg --add-architecture i386
sudo mkdir -pm755 /etc/apt/keyrings
sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
sudo apt update && sudo apt install --install-recommends winehq-stable
  1. 完善package.json的maker配置
    确保@electron-forge/maker-squirrel的配置完整,补充必要的应用信息,示例如下:
"makers": [
  {
    "name": "@electron-forge/maker-squirrel",
    "config": {
      "name": "your_app_id",
      "authors": "Your Name",
      "version": "1.0.0"
    }
  },
  // 保留原有Linux平台的maker配置
  {
    "name": "@electron-forge/maker-deb",
    "config": {}
  },
  {
    "name": "@electron-forge/maker-rpm",
    "config": {}
  }
]
  1. 指定Windows平台执行打包
    运行打包命令时明确指定目标平台为Windows,Electron Forge会自动调用Wine完成构建:
npx electron-forge make --platform win32

执行完成后,你将在/out/make目录下看到Windows相关的安装包文件(如.exe安装程序及Squirrel生成的配套目录)。

额外注意事项

  • 确保Electron Forge及相关依赖为最新版本,避免兼容性问题:
npm install --save-dev @electron-forge/cli @electron-forge/maker-squirrel
  • 若Wine运行出现异常,可尝试安装Wine的补充依赖库,或切换至Wine开发版(优先推荐稳定版)。

内容的提问来源于stack exchange,提问作者Raphael10

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 22:21:01