常用Electron App打包工具

<a >
electron-banner

</a>

引言

在打包Electron App的時(shí)候,有很多工具可以使用,各有長(zhǎng)短,這里簡(jiǎn)單匯總幾個(gè)常用工具的特點(diǎn)及注意事項(xiàng),便于選擇。包括:

  • electron-packager;
  • electron-builder;
  • grunt-electron-installer(windows-installer);

注意:詳細(xì)的安裝及使用方法需要參考官方文檔,本文不做贅述。

electron-packager

官方鏈接

是什么

Package your Electron app into OS-specific bundles (.app, .exe, etc.) via JavaScript or the command line.
Electron Packager is a command line tool and Node.js library that bundles Electron-based application source code with a renamed Electron executable and supporting files into folders ready for distribution.

使用方法

該工具提供了兩種使用方式:JS API(Node.js library)和CLI。詳細(xì)使用方法請(qǐng)?jiān)L問官方文檔。下面是在命令行中使用的例子:

"scripts": {
    "package": "electron-packager . --platform=win32 --arch=ia32 --electron-version=1.4.15 --overwrite --ignore=node_modules --ignore=.gitignore"
},

特點(diǎn)

  • 使用 electron-packager 打包,macOS系統(tǒng)打包app文件,不能打包exe文件,windows系統(tǒng)可以打包app文件以及exe文件;
  • 支持平臺(tái)有:Windows (32/64 bit)、OS X (also known as macOS)、Linux (x86/x86_64);
  • 生成的格式:.exe(這里不能生成安裝包,只能生成可執(zhí)行文件及目錄)、.app、mas、linux可執(zhí)行格式;
  • 可選項(xiàng)
  • 支持CLI和JS API兩種使用方式;

electron-builder

官方連接

是什么

A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out of the box.

使用方法

在 package.json中添加如下配置:

"scripts": {
    "pack": "build --win --ia32 --dir",
    "dist": "build --win --ia32"
},
"build": {
    "appId": "org.shennongmin.QuickStart",
    "copyright": "Open Totally",
    "compression": "normal",
    "nsis": {
        "oneClick": true,
        "perMachine": true,
        "runAfterFinish": true
    }
},

特點(diǎn)

  • electron-builder 可以打包成msi、exe、dmg文件,macOS系統(tǒng),只能打包dmg文件,window系統(tǒng)才能打包exe,msi文件;
  • 幾乎支持了所有平臺(tái)的所有格式;
  • 可以將prepackage目錄(手動(dòng)或使用electron-packager生成的目錄)打包成安裝包;
  • 支持Auto Update
  • 非常豐富的選項(xiàng)
  • 支持CLI和JS API兩種使用方式;

grunt-electron-installer

官方鏈接

https://github.com/electron-archive/grunt-electron-installer

是什么

Grunt plugin that builds Windows installers for Electron apps using Squirrel.

使用方法

先用 electron-packager 將應(yīng)用打包到應(yīng)用目錄下,例如:SNM Quick Start-win32-ia32

在應(yīng)用目錄下新文件 gruntPackage.json,內(nèi)容如下:

{
    "name": "SNM_Quick_Start",
    "version": "1.7.8"
}

在應(yīng)用目錄下新文件 Gruntfile.js,內(nèi)容如下:

var grunt = require("grunt");
grunt.config.init({
        pkg: grunt.file.readJSON('gruntPackage.json'),
        'create-windows-installer': {
                ia32: {
                        appDirectory: 'SNM Quick Start-win32-ia32',
                        authors: 'shen nongmin',
                        exe: 'SNM Quick Start.exe',
                        description: "this is a test",
                }       
        }
})

grunt.loadNpmTasks('grunt-electron-installer');
grunt.registerTask('default', ['create-windows-installer']);

安裝grunt和grunt-electron-installer:

npm install -g grunt-cli
npm install grunt grunt-electron-installer --save-dev

在應(yīng)用目錄下執(zhí)行g(shù)runt:

grunt

隨后會(huì)在生成的installer目錄中包含如下幾個(gè)文件:

RELEASES
SNM Quick StartSetup.exe
SNM Quick StartSetup.msi
SNMQuickStart-1.7.8-full.nupkg

其中,.exe可以安裝(如需支持Squirrel則需要對(duì)main.js進(jìn)行修改,這里不介紹)。

特點(diǎn)

關(guān)于支持Squirrel的鏈接


閱讀原文 | 作者官網(wǎng) | 公眾號(hào) | Feed | 訂閱 | 發(fā)私信

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容