背景:之前用electron-packager将web项目打包成客户端时,exe文件只能在当前文件夹下运行,如果发送给别人使用 极不方便。所以我们可以用electron-builder将web项目封装成安装包给别人使用。

1、配置npm代理

npm set electron_mirror=https://npm.taobao.org/mirrors/electron/
npm set electron-builder-binaries_mirror=https://npm.taobao.org/mirrors/electron-builder-binaries/

2、新建main.js

// Modules to control application life and create native browser window
const {app, BrowserWindow,Menu} = require('electron')
const path = require('path')
//因为项目使用server,添加了这个库,添加前,别忘了使用 npm i http-server 安装库。
const httpServer = require('http-server'); function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
}) // and load the index.html of the app.
// mainWindow.loadFile('index.html') // Open the DevTools.
// mainWindow.webContents.openDevTools()
//注意 这里是我添加的,去掉electron自带菜单
Menu.setApplicationMenu(null)
mainWindow.loadFile('dist/index.html')
httpServer.createServer({root:"./dist"}).listen(80); } // This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow() app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
}) // Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
}) // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

3、新建package.json

{
"name": "apiadmin",
"version": "4.0.0",
"author": "zhaoxiang <zhaoxiang051405@gmail.com>",
"private": false,
"scripts": {
"view": "electron .",
"build": "electron-builder"
},
"main": "main.js",
"build": {
"productName":"nullmax",
"appId": "com.wss.app",
"directories": {
"output": "builder"
},
"nsis": {
"oneClick": false,
"allowElevation": true,
"allowToChangeInstallationDirectory": true,
"installerIcon": "./logo.ico",
"uninstallerIcon": "./logo.ico",
"installerHeaderIcon": "./logo.ico",
"createDesktopShortcut": true,
"createStartMenuShortcut": true,
"shortcutName": "nullmax"
},
"win": {
"target": [
"nsis",
"zip"
]
},
"files": [
"dist/**/*",
"main.js"
]
},
"dependencies": {
"http-server": "^14.1.1"
}
}

package.json解释:http://www.45fan.com/article.php?aid=1CODrX8UJM4TUTnc

"build": {
"productName":"xxxx",//项目名 这也是生成的exe文件的前缀名
"appId": "com.leon.xxxxx",//包名
"copyright":"xxxx",//版权 信息
"directories": { // 输出文件夹
"output": "build"
},
"nsis": {
"oneClick": false, // 是否一键安装
"allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
"allowToChangeInstallationDirectory": true, // 允许修改安装目录
"installerIcon": "./build/icons/aaa.ico",// 安装图标
"uninstallerIcon": "./build/icons/bbb.ico",//卸载图标
"installerHeaderIcon": "./build/icons/aaa.ico", // 安装时头部图标
"createDesktopShortcut": true, // 创建桌面图标
"createStartMenuShortcut": true,// 创建开始菜单图标
"shortcutName": "xxxx", // 图标名称
"include": "build/script/installer.nsh", // 包含的自定义nsis脚本
},
"publish": [
{
"provider": "generic", // 服务器提供商 也可以是GitHub等等
"url": "http://xxxxx/" // 服务器地址
}
],
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/icon.icns"
},
"win": {
"icon": "build/icons/aims.ico",
"target": [
{
"target": "nsis",
"arch": [
"ia32"
]
}
]
},
"linux": {
"icon": "build/icons"
}
}

4、打包

npm run build

发送 apiadmin Setup 4.0.0.exe给他人装即可

使用Electron-builder将web项目封装客户端安装包 发布的更多相关文章

  1. Linux CentOS7下svn+tomcat9.0+maven3.3+jenkins实现web项目自动构建与远程发布

    CentOS7下svn+tomcat9.0+maven3.3+jenkins实现web项目自动构建与远程发布 by:授客 QQ:1033553122 目录 一.    实践环境. 1 二.    安装 ...

  2. 使用node-webkit(v0.35.5)和innosetup(3.6.1)打包将web程序打包为桌面客户端(安装包)

    这边主要是有一个客户,需要在电视机上安装一个客户端,含有视频直播功能:刚开始我们采用的webapp打包成apk安装在电视机上,发现摄像头监控画面根本无法播放(apk在手机上可以正常播放视频):排除一些 ...

  3. 带领技术小白入门——基于java的微信公众号开发(包括服务器配置、java web项目搭建、tomcat手动发布web项目、微信开发所需的url和token验证)

    微信公众号对于每个人来说都不陌生,但是许多人都不清楚是怎么开发的.身为技术小白的我,在闲暇之余研究了一下基于java的微信公众号开发.下面就是我的实现步骤,写的略显粗糙,希望大家多多提议! 一.申请服 ...

  4. electron热更新与windows下的安装包

    帮朋友公司做了点东西,他说有很多bug,我一看,基本问题都是浏览器兼容引起的,而electron内带Chromium内核,正好一直想尝试下electron,所以研究了一波.这里只是简单的使用elect ...

  5. cordova 安卓项目打包 release安装包

    问题描述: 打包安卓项目, 如果是在项目中只是使用debug包的话, 其中的签名方式使用的都是cordova框架本身, 那么每次打包的话, 都会把之前的安装包给覆盖掉. 现在打包做出一个release ...

  6. JAVA web项目转客户端(nativefier)

    1.环境:windows 2.下载node.js 3.安装mode.js;记住安装目录 4.命令行进入安装目录 5.执行语句: npm install nativefier –g 进行安装 6.新建空 ...

  7. Java Web项目获取客户端和服务器的IP地址

    在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的.但是在通过了Apache,Squid等反向代理软件就不能获取到客户端的真实I ...

  8. web项目从域名申请到发布

    http://wenku.baidu.com/link?url=H-Hu2nvzFRirdxO3xzrWCWfc4WJFLyFjsxak5MFwOuzQfgTawJLXC4vAc4xYAIySxn59 ...

  9. 微信公众号开发 包括服务器配置、java web项目搭建、tomcat手动发布web项目、微信开发所需的url和token验证 2017.12.2

    https://www.cnblogs.com/klmei/p/7060879.html  基础配置很全面

  10. 如何使用VS将项目生成一个安装包?

    VS2010项目的部署与安装winform程序,我想进行安装.1.在解决方案中 ——点击右键——添加 2.然后选择 安装和部署 ——安装向导 可以更改名称 3.点击 下一步 4.然后选择上那3个 5. ...

随机推荐

  1. react导入的插件不支持服务端渲染报错的解决方法

    正常的导入方法如下: import { useEffect, useState, useRef } from 'react'; 如果不支持服务端渲染的插件这样导入则会报错(具体的报的什么错我忘了),一 ...

  2. 【Hive】数据倾斜原因及解决方法汇总

    1)数据倾斜根本原因:由于数据分布不均匀,导致map端读取的数据分布不均匀(数据长尾分布),从而使得map处理的数据量差异过大. (2)解决思路:Hive是分阶段执行的,map处理数据量的差异取决于上 ...

  3. Liunx安装Docker

    1.更新yum包到最新 sudo yum update 2.卸载历史Docker,如果没有安装过,则跳过该步 sudo yum remove docker \ docker-client \ dock ...

  4. PHP操作MySQL批量Update的写法,各框架通用防注入版

    使用别人的扩展遇到了问题,发现没有做SQL注入的处理.我又写了个轮子,根据自己需求扩展了下,有需要的小伙伴可以直接取用. 这里就直接粘贴源码了,会用PHPD ,基本都会如何把它运用到各个框架里的. 本 ...

  5. ROM,RAM,内存

    ROM是用来存放最基本的程序的,不是系统程序(windows),而是主板自带的最基本的程序, 无法被删除,更改.只能读取. 操作系统是放在硬盘里的,在开机时会在内存中加载,所以windows7比win ...

  6. go写文件常用方法

    注意:打开文件,一定记得关闭 file, err := os.OpenFile(name, flag, perm) defer file.Close() 一.打开文件|创建 1.os.OpenFile ...

  7. porps传参

    porps传参(最常用的 布尔传值)(基于前面的步骤进行修改) ①index.js //定义动态路由 props:trueconst routes =[ {path:"/user/:id/: ...

  8. 我做的mysql 一些题 里面大部分都是mysql的方法

    基础题:-- 1. 查询Student表中的所有记录的Sname.Ssex和Class列.1 select sname,ssex,class from student;-- 2. 查询教师所有的单位即 ...

  9. Python之简单文件操作

    文件操作,open() 1 # open(file_path, mode='r', encoding='utf-8') 2 # file_path 目标文件路径 3 # mode 文件模式,参数r-读 ...

  10. Oracle数据库安装时,安装报错ins_emagent.mk

    安装oracle数据库过程中,通过图形界面安装,出现ins_emagent.mk报错提示 解决方法 修改$ORACLE_HOME/sysman/lib/ins_emagent.mk,将$(MK_EMA ...