electron-builder 打包流程

在使用electron-builder 打包时的一些心得希望可以帮助更多的人解决问题

一、安装 electron-builde  在此之前必须先安装yarn   当然用npm也可以只是网络不太好

yarn add electron-builder --save-dev

二、配置package.json

{
  "name": "crjgui",
  "version": "0.0.0",
  "author": "samtiger <2669667558@qq.com>",
  "description": "An electron-vue project",
  "license": null,
  "main": "./dist/electron/main.js",
  "scripts": {
    "build": "node .electron-vue/build.js && electron-builder",
    "build:dir": "node .electron-vue/build.js && electron-builder --dir",
    "build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
    "build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
    "dev": "node .electron-vue/dev-runner.js",
    "e2e": "npm run pack && mocha test/e2e",
    "pack": "npm run pack:main && npm run pack:renderer",
    "pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
    "pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
    "test": "npm run unit && npm run e2e",
    "unit": "karma start test/unit/karma.conf.js",
    "postinstall": ""
  },
  "build": {
    "productName": "出国(境)证件管理系统",  //项目名称
    "appId": "org.simulatedgreg.electron-vue",  //包名
    "copyright":"航星永志版权所有",  //版权所有
    "directories": {
      "output": "dist" //输出文件夹
    },
  "nsis": {
      "oneClick": false, // 一键安装
      "allowElevation": true, // 允许请求提升。 如果为false,则用户必须使用提升的权限重新启动安装程序。
      "allowToChangeInstallationDirectory": true, // 允许修改安装目录
      "createDesktopShortcut": true, // 创建桌面图标
      "createStartMenuShortcut": true, // 创建开始菜单图标
      "shortcutName": "xxxx" // 图标名称
      "installerIcon": "./build/icons/aaa.ico", // 安装图标
      "uninstallerIcon": "./build/icons/bbb.ico", //卸载图标
      "installerHeaderIcon": "./build/icons/aaa.ico", // 安装时头部图标
      "include": "build/script/installer.nsh" //配置 nsn
    },
"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/icon.ico",
      "target": [
        {
          "target": "nsis",
          "arch": [
            "ia32"
          ]
        }
      ]
    },
    "linux": {
      "icon": "build/icons"
    }
  },
  "dependencies": {
   ...
  },
  "devDependencies": {
    ...
  }
}

 三、把installer.nsh 文件放到指定位置   也就是 在 nsis 下  include 的位置

 demo地址:https://gitee.com/chengxiang666/electron-builderDemo/tree/master

 

posted @ 2019-11-15 11:14  First·林肯  阅读(4082)  评论(0编辑  收藏  举报