1:package.json
通过npm init生成package.json文件,内容如下:
{ "name": "t02", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "start": "electron ." }, "dependencies": { "electron": "~1.6.2" }, "devDependencies": { "electron": "~1.6.2" }, "author": "", "license": "ISC" }
2:app.js
const electron = require('electron'); const app = electron.app; const BrowserWindow = electron.BrowserWindow; app.on('ready', function() { mainWindow = new BrowserWindow({ width: 400, height: 300 }); mainWindow.loadURL('file://' + __dirname + '/app.html'); mainWindow.on('closed', function() { mainWindow = null; }); });
3:app.html
<!doctype html> <html> <head> <title>My First Electron App</title> <style type="text/css"> body { margin: 0; } textarea { width: 100%; border: none; background: #eee; margin: 10px 0; padding: 0; outline: none; } </style> </head> <body> <textarea rows="10"></textarea> </body> </html>
4:运行
(1)安装node_modules
D:\electron_ws\t02>npm install
(2)运行
D:\electron_ws\t02>electron .