# 3.第一个应用

# 1.创建一个项目文件夹

# 2.npm init -y 初始化

# 3.修改package.json

{
  "name": "01-electron-helloworld",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "electron": "^11.1.1"
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 4.初始化一个html文件

# 5.初始化main.js

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

function createWindow() {
    const win = new BrowserWindow({
        width:800,
        height: 600,
        // 在html使用node语法
        webPreferences: {
            nodeIntegration: true
        }
    })

    win.loadFile('index.html')
}

app.on('ready', createWindow)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 6.运行

npm run start
1
上次更新: 2021/2/21 下午7:52:17