一、Electron入门教程

参考资料:https://www.cnblogs.com/zhangshuda/p/8086500.html

一、首先安装node(具体过程百度)

二、新建文件夹demo

三、打开终端进入新建的文件夹中

4、初始化项目 npm init -f

 文件中会多出package.json文件

 

五、修改package.json

  main:'index.js'修改为  main:'main.js'

六、安装electron

  npm install electron --save  //也可用 cnpm install electron --save

  项目中会多出node_modules文件夹

  oacjage.json会加入electron相关的配置

 

 七、项目根目录下新建main.js

const electron = require('electron')
const path = require("path")
const url = require('url')

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

let mainWindow

function createWindow () {
    // Create the browser window.
    mainWindow = new BrowserWindow({width: 900, height: 600})
    var webContents=mainWindow.webContents;
    //开启开发者工具
    webContents.openDevTools();
    // and load the index.html of the app.
    mainWindow.loadURL(url.format({
        pathname: path.join(__dirname, 'index.html'),
        protocol: 'file:',
        slashes: true
    }))

    // Open the DevTools.
    // mainWindow.webContents.openDevTools()

    // Emitted when the window is closed.
    mainWindow.on('closed', function () {
        // Dereference the window object, usually you would store windows
        // in an array if your app supports multi windows, this is the time
        // when you should delete the corresponding element.
        mainWindow = null
    })
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)

// Quit when all windows are closed.
app.on('window-all-closed', function () {
    // On OS X it is common for applications and their menu bar
    // to stay active until the user quits explicitly with Cmd + Q
    if (process.platform !== 'darwin') {
        app.quit()
    }
})

app.on('activate', function () {
    // On OS X it's common to re-create a window in the app when the
    // dock icon is clicked and there are no other windows open.
    if (mainWindow === null) {
        createWindow()
    }
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

 

八、项目根目录下创建index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <h1>hello world</h1>
</body>
</html>

 

九、修改package.json 

  

{
  "name": "waterdroplets",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "electron": "^2.0.6"
  },
  "devDependencies": {
    "devtron": "^1.4.0"
  }
}

 

十、在项目跟目录下 终端执行 npm start

  

 

转载于:https://www.cnblogs.com/kongnengjing/p/9414727.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值