electron使用builder打包

1、安装npm install --save-dev electron-builder

2、修改package.json,添加build

 "build": {
   "appId": "com.example.app",
   "asar": true,
   "asarUnpack": "path/to/unpacked/files",
   "files": [ //打包时包含的文件
     "dist",
     "node_modules",
     "package.json",
     "main.js", //没有的话,无法正常打包
     "index.html" //没有的话,界面无法正常显示
   ],
   "directories": {
     "output": "release",
     "buildResources": "build-resources"//资源路径(根目录下创建资源文件夹,可以放各平台的icon)
   },
   "mac": {
     "category": "public.app-category.developer-tools",
     "target": "dmg",
     "icon": "build-resources/icon.icns" //图标路径
   },
   "win": {
     "target": "nsis",
     "icon": "build-resources/icon.ico" //图标路径
   },
   "linux": {
     "target": "deb",
     "icon": "build-resources/icon.png" //图标路径
   }
 }

3、package.json完整版

{
  "name": "excel-to-json-tools",
  "version": "1.0.0",
  "description": "A minimal Electron application",
  "main": "main.js",
  "scripts": {
    "start": "electron-forge start",
    "package": "electron-forge package",
    "make": "electron-forge make"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/electron/electron-quick-start.git"
  },
  "keywords": [
    "Electron",
    "quick",
    "start",
    "tutorial",
    "demo"
  ],
  "author": "GitHub",
  "license": "CC0-1.0",
  "devDependencies": {
    "@electron-forge/cli": "^7.4.0",
    "@electron-forge/maker-deb": "^7.4.0",
    "@electron-forge/maker-rpm": "^7.4.0",
    "@electron-forge/maker-squirrel": "^7.4.0",
    "@electron-forge/maker-zip": "^7.4.0",
    "@electron-forge/plugin-auto-unpack-natives": "^7.4.0",
    "@electron-forge/plugin-fuses": "^7.4.0",
    "@electron/fuses": "^1.8.0",
    "electron": "^32.0.1",
    "electron-builder": "^24.13.3"
  },
  "bugs": {
    "url": "https://github.com/electron/electron-quick-start/issues"
  },
  "homepage": "https://github.com/electron/electron-quick-start#readme",
  "dependencies": {
    "electron-squirrel-startup": "^1.0.1",
    "xlsx": "^0.18.5"
  },
  "build": {
    "appId": "com.example.app",
    "asar": true,
    "asarUnpack": "path/to/unpacked/files",
    "files": [ //打包时包含的文件
      "dist",
      "node_modules",
      "package.json",
      "main.js", //没有的话,无法正常打包
      "index.html" //没有的话,界面无法正常显示
    ],
    "directories": {
      "output": "release",
      "buildResources": "build-resources"//资源路径(根目录下创建资源文件夹,可以放各平台的icon)
    },
    "mac": {
      "category": "public.app-category.developer-tools",
      "target": "dmg",
      "icon": "build-resources/icon.icns" //图标路径
    },
    "win": {
      "target": "nsis",
      "icon": "build-resources/icon.ico" //图标路径
    },
    "linux": {
      "target": "deb",
      "icon": "build-resources/icon.png" //图标路径
    }
  }
}

4、打包
mac平台,npx electron-builder build --mac(使用mac打包)
window平台,npx electron-builder build --win

5、打包时打开开发者模式否则可能无法创建符号链接,解压失败。解决办法打开开发者模式。
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值