Electron初步

Electron文檔html

mkdir myapp
cd myapp
npm init

生成的package.json以下,而後添加一行"start": "electron ."git

{
  "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作版本控制github

npm install electron --save-dev
# 全局安裝
npm install electron -g

package.json文件更新以下npm

"devDependencies": {
    "electron": "^3.0.1"
  }

當前目錄下新建index.js文件 https://github.com/electron/e...json

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便可查看效果。api

Electron API 演示應用程序bash

相關文章
相關標籤/搜索