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、打包时打开开发者模式否则可能无法创建符号链接,解压失败。解决办法打开开发者模式。