Electron初步
mkdir myapp cd myapp npm init
生成的package.json如下,然后添加一行"start": "electron ."
{ "name": "journal", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "electron ." }, "keywords": [ "journal" ], "author": "Octo", "license": "ISC", }
安装electron,也可全局安装,不过不好对不同app做版本控制
npm install electron --save-dev # 全局安装 npm install electron -g
package.json文件更新如下
"devDependencies": { "electron": "^3.0.1" }
当前目录下新建index.js文件 https://github.com/electron/e...
const { app, BrowserWindow } = require("electron"); let mainWindow; function createWindow() { mainWindow = new BrowserWindow({ width: 800, height: 600 }); mainWindow.loadFile("../src/index.html"); mainWindow.on("closed", function() { mainWindow = null; }); }; app.on("ready", createWindow); app.on("window-all-closed", function() { if (process.platform !== "darwin") { app.quit(); } }); app.on("activate", function() { if (mainWindow === null) { createWindow(); } });
运行npm start
即可查看效果。
相关推荐
游走的豚鼠君 2020-11-10
sanallen 2020-07-04
electronvolt 2020-07-04
sanallen 2020-06-14
moyigg 2020-06-09
疯狂老司机 2020-06-07
zhujuyu 2020-06-06
moyigg 2020-06-01
zhujuyu 2020-05-30
viewerlin 2020-05-29
zhujuyu 2020-05-28
yanchuncheng 2020-05-12
Trustport 2020-05-06
chenyijun 2020-05-05
electronvolt 2020-05-04
游走的豚鼠君 2020-05-01
electronvolt 2020-04-21
游走的豚鼠君 2020-04-18