{ "name": "electron-quick-start", "version": "1.0.0", "description": "A minimal Electron application", "main": "main.js", "scripts": { "start": "electron .", "win": "electron-packager . Bcreat --platform=win32 --arch=x64 --icon=icon.ico --out=./dlist --asar --app-version=0.0.1", "winexe": "electron-builder --win --x64" }, "repository": "https://github.com/electron/electron-quick-start", "keywords": [ "Electron", "quick", "start", "tutorial", "demo" ], "build": { "appId": "com.bcreatexe.app", "nsis": { "oneClick": false, "allowElevation": true, "allowToChangeInstallationDirectory": true, "installerIcon": "./icon.ico", "uninstallerIcon": "./icon.ico", "installerHeaderIcon": "./icon.ico", "createDesktopShortcut": true, "createStartMenuShortcut": true }, "win": { "target": "nsis" } }, "author": "GitHub", "license": "CC0-1.0", "devDependencies": { "electron-builder": "^22.10.5", "electron": "^12.0.5" }, "dependencies": { "electron-packager": "^15.2.0" } }
将上面代码修改根目录package.json文件,注意你改成你自己的项目名称~
常用electron打包方式分两种
一、electron-packager
含义就打包成直接运行包,可以直接打开exe运行
二、electron-builder
含义就是打包成安装版,可以自定义安装路径,安装图标,创建桌面快捷方式等,运行exe,打开开始安装
运行方式:npm run win (就是运行electron-packager打包方式)、npm run winexe (就是运行electron-builder打包方式),具体的代码在上面代码scripts参数里面~