【electron】electron入门打包

启动

# Clone this repository
git clone 
# Go into the repository
cd electron-quick-start
# Install dependencies
npm install
# Run the app
npm start

打包

# 配置加载外部地址
mainWindow.loadURL("");

# 安装electron-packager
npm install electron-packager --save-dev

# 在package.json中配置打包命令
"package": "electron-packager . dc-hmsk --out ./dist --arch=x64 --overwrite"

# npm执行打包
npm run-script package

# 打包完成可以在./dist中查看

打包成windows安装文件

# 安装electron-winstaller
npm install --save-dev electron-winstaller

# 创建一个builder.js,并且引入如下内容

var electronInstaller = require('electron-winstaller');
var path = require("path");

resultPromise = electronInstaller.createWindowsInstaller({
    appDirectory: path.join('./dist/dc-hmsk-win32-x64'), //刚才生成打包文件的路径
    outputDirectory: path.join('./tmp/build/installer64'), //输出路径
    authors: 'hwj', // 作者名称
    exe: 'dc-hmsk.exe', //在appDirectory寻找exe的名字
    noMsi: true, 
});

resultPromise.then(() => console.log("It worked!"), (e) => console.log(`No dice: ${e.message}`));

# 安装electron-squirrel-startup
npm i electron-squirrel-startup --save

# 修改代码在main.js中引入如下代码(解决安装包重复启动问题)
if(require('electron-squirrel-startup')) return;

# 执行打包windows安装文件
node builder.js

你可能感兴趣的:(前端,electron,javascript,vue.js)