博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
electron开发
阅读量:2389 次
发布时间:2019-05-10

本文共 2657 字,大约阅读时间需要 8 分钟。

安装NodeJS

目前支持的最新版本为NodeJS 7.4.0,因为安装过程比较简单所以这里省略了。

安装Electron

npm install -g electron

创建项目工程

使用WebStorm创建一个Empty Project.

用npm init初始化这个项目。初始化后,package.json内容如下

{  "name": "facerecognition_test",  "version": "1.0.0",  "description": "",  "main": "main.js",  "scripts": {    "start": "electron .",    "pack": "electron-packager --electron-version=16.11 .",    "build": "build "  },  "author": "Chen Haifeng",  "license": "ISC"}

添加文件index.html

    
人脸识别测试程序
添加文件main.js

const {app, BrowserWindow} = require('electron')const path = require('path')const url = require('url')//import url from "url"// Keep a global reference of the window object, if you don't, the window will// be closed automatically when the JavaScript object is garbage collected.let winfunction createWindow () {    console.log('createWindow')    // Create the browser window.    win = new BrowserWindow({width: 800, height: 600})    // and load the index.html of the app.    win.loadURL(url.format({        pathname: path.join(__dirname, 'index.html'),        protocol: 'file:',        slashes: true    }))    // Open the DevTools.    win.webContents.openDevTools()    // Emitted when the window is closed.    win.on('closed', () => {        // Dereference the window object, usually you would store windows        // in an array if your app supports multi windows, this is the time        // when you should delete the corresponding element.        win = null    })}// 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.on('ready', createWindow)// Quit when all windows are closed.app.on('window-all-closed', () => {    // On macOS it is common for applications and their menu bar    // to stay active until the user quits explicitly with Cmd + Q    if (process.platform !== 'darwin') {        app.quit()    }})app.on('activate', () => {    // 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 (win === null) {        console.log('activate')        createWindow()    }})// 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.
测试项目

如果electron是采用全局安装的,使用electron .来运行项目。

如果electron是安装在项目的node_modules目录,使用.\node_modules\.bin\electron .来运行项目。

因为在package.json文件中做了配置,所以这里可以使用npm start运行项目。

打包项目

安装electron-packager

npm install -g electron-packager

electron-packager --electron-version=1.6.11 .

生成结果如下

运行一下打包后的exe程序

制作平台安装包

npm install -g electron-builder

执行命令build, 整个过程比较漫长。 

自动更新下次补充。

你可能感兴趣的文章
弗洛伊德(Floyd)算法 Java实现
查看>>
拓扑排序(TopologicalSort) Java实现
查看>>
关键路径算法 Java实现
查看>>
PreparedStatement,hibernate查询oracle char类型解决方案
查看>>
ThreadLocal Pager 分页的一种解决方案 (hibernate)
查看>>
二叉排序树(Binary Sort Tree)查找、插入、删除 Java实现
查看>>
平衡二叉树(AVL树)算法 Java实现
查看>>
Middle-题目37:199. Binary Tree Right Side View
查看>>
linux下载edk2链接文件
查看>>
Win10家庭版DOCKER安装(上)
查看>>
Win10家庭版DOCKER安装(下)
查看>>
docker 图形化管理工具Kitematics
查看>>
unittest单元测试框架总结
查看>>
command 'x86_64-linux-gnu-gcc' failed with exit status 1
查看>>
浅谈前端SPA(单页面应用)
查看>>
Insecure default in Elasticsearch enables remote code execution
查看>>
how to use this bugs unserialize()
查看>>
PHP5 Globals Vulnerability
查看>>
关于php包含Apache日志的随想
查看>>
Grep与web漏洞挖掘
查看>>