美文网首页
Electron 打包桌面应用

Electron 打包桌面应用

作者: 不得了了赶紧跑 | 来源:发表于2017-06-11 17:06 被阅读0次

    Electron中文文档:https://www.kancloud.cn/simon_chang/electron/227449

    • 首先下载electron环境
    git clone https://github.com/electron/electron-quick-start.git
    cd electron-quick-start
    cnpm install && npm start
    

    此时通过 <code>npm start</code> 就可以打包并启动应用了,但此时并没有安装程序

    • 安装打包程序
    cnpm install electron-packager --save-dev
    

    并在package.json中script里添加

    "package": "electron-packager ./ wplay --win --out wplay --arch=x64 --version 1.6.10 --overwrite --ignore=node_modules"
    

    参数说明
    electron-packager <location of project> <name of project> <platform> <architecture> <electron version>
    location of project:应用目录;
    name of project:应用名称;
    platform:要打包的平台;
    architecture:x86 or x64架构;
    electron version:electron 版本(不是应用版本);
    optional options:其它选项;

    此时可以通过 <code>npm run package</code> 生成exe文件,可能因为gfw的原因下载特别慢,注意下package的版本信息,然后点击 http://npm.taobao.org/mirrors/electron 选择对应版本下载

    • 进入<code>electron-packager</code>生成的文件夹内,安装 <code>grunt-electron-installer</code> 和<code>grunt</code>
    cnpm install grunt-electron-installer --save-dev
    cnpm install grunt --save-dev
    

    此时的文件结构:


    文件结构

    新建文件 <code>package.json</code>,填入名称以及版本信息,<code>npm install</code> 将会添加其他依赖信息

      "name": "wplay",
      "version": "1.0.0",
    

    如图:


    package.json

    新建文件 <code>Gruntfile.js</code>

    var grunt = require("grunt");
    grunt.config.init({
        pkg: grunt.file.readJSON('package.json'),
        'create-windows-installer': {
            x64: {
                appDirectory: 'f:/code/wplay/wplay/wplay-win32-x64',
                authors: 'kelrvins',
                exe: 'wplay.exe',
                title:'wplay',
                outputDirectory:'./out',
                description:"wplay",
            }       
        }
    })
    grunt.loadNpmTasks('grunt-electron-installer');
    grunt.registerTask('default', ['create-windows-installer']);
    

    配置说明:


    配置说明

    -通过命令 <code>grunt</code> 生成安装包


    生成安装包
    • 遇到的坑:
      1、路径有误找不到文件:使用绝对地址
      2、报很长一段的错误,错误码结尾是25:exe中后缀名也要写

    相关文章

      网友评论

          本文标题:Electron 打包桌面应用

          本文链接:https://www.haomeiwen.com/subject/fswhqxtx.html