Electron Create desktop applications

Source: Internet
Author: User
Electron Create desktop applications

Electron Create desktop Application Add Taobao NPM mirrored install electron create application Packagejson MAINJS indexhtml Run application

add Taobao NPM Mirror

Do not say anything, before work to add Taobao NPM mirror image, or behind the installation module will be stuck.

$ sudo npm install-g cnpm--registry=https://registry.npm.taobao.org
Install electron

Here I am using the global

$ sudo cnpm install-g electron
Create an application

The directory structure of a electron application is roughly as follows:

myapp/
├──package.json
├──main.js
└──index.html
Package.json
{
  "name": "MyApp", "
  Version": "0.1.0",
  "main": "Main.js",
  "scripts": {
    "start": "Electron Main.js "
  }
}
Main.js
const {app, Browserwindow} = require (' electron ');
Const PATH = require (' path ');
Const URL = require (' URL ');

Let win;

function CreateWindow () {
  win = new Browserwindow ({width:800, height:600});

  Win.loadurl (Url.format ({
    pathname:path.join (__dirname, ' index.html '),
    protocol: ' File: ',
    slashes: True
  });

  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>
Run the application

Go to the application directory and run

$ electron.

In addition, as we have defined in the Package.json file

  ...
  " Scripts ": {
    " start ":" Electron Main.js "
  }

So you can also use NPM to run

$ NPM Install
$ npm Start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.