Recently idle to have nothing to do, play with electron.
1, installation Nodejs
: http://nodejs.cn/download/, download 64-bit. After the installation is complete, open the C:\Program files\nodejs\node_modules\npm directory, edit the NPMRC file, and add Electron_mirror= "https://npm.taobao.org/mirrors/electron/". Add an electron image.
2. Create a new folder Desktopapp, and then create a new three files:
Main.js Main logic files
Index.html page File
Package.json Nodejs Standard File
Under the Desktopapp folder, run the NPM install electron. After the installation is complete, automatically generate: Package-lock.json and Node_modules folders.
3. main.js file
Const ELECTRON = require (' electron '); Const app=Electron.app;const Browserwindow=Electron. Browserwindow;varMainWindow =NULL; App.on (' Window-all-closed ',function() { if(Process.platform! = ' Darwin ') {app.quit (); }}); App.on (' Ready ',function() {MainWindow=NewBrowserwindow ({width:800, height:600}); Mainwindow.loadurl (' file://' + __dirname + '/index.html '); Mainwindow.on (' Closed ',function() {MainWindow=NULL; });});
4. Package.json file
{ "name": "Desktopapp", "version": "0.1.0", "main": "Main.js", "Dependencies": { "electron": "^1.6.11" }}
5. index.html File
<!DOCTYPE HTML><HTML> <Head> <title>Hello world!</title> </Head> <Body> <H1>Hello world!</H1>We are using Io.js<Script>document.write (process.version)</Script>and Electron<Script>document.write (process.versions['Electron'])</Script>. </Body></HTML>
6. Operation:
c:\> D:\DesktopApp\node_modules\electron\dist\electron.exe D:\DesktopApp
(Executes the project using an EXE file of a locally installed electron)
A preliminary study of Windows Electron