Skip to content

Instantly share code, notes, and snippets.

@lqqyt2423
Created March 3, 2019 13:19
Show Gist options
  • Save lqqyt2423/42cbd2e926f0443b8be1ed892ccf78b4 to your computer and use it in GitHub Desktop.
Save lqqyt2423/42cbd2e926f0443b8be1ed892ccf78b4 to your computer and use it in GitHub Desktop.
electron quick start
ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" npm i electron --save-dev

package.json

{
  "name": "tmp",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "electron": "^4.0.6"
  }
}

index.js

'use strict';

const { app, BrowserWindow } = require('electron');

let win;

function createWindow () {
  win = new BrowserWindow({ width: 800, height: 600 });
  win.loadFile('index.html');
  win.webContents.openDevTools();

  win.on('closed', () => {
    win = null;
  });
}

app.on('ready', createWindow);

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (win === null) {
    createWindow();
  }
});

index.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Hello World!</title>
</head>

<body>
  <h1>Hello World!</h1>
  We are using node
  <script>document.write(process.versions.node)</script>,
  Chrome
  <script>document.write(process.versions.chrome)</script>,
  and Electron
  <script>document.write(process.versions.electron)</script>.
</body>

</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment