环境搭建总览
git clone https://github.com/nvm-sh/nvm.git
或
git clone https://gitcode.net/mirrors/nvm-sh/nvm.git
bash install.sh
NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_REPO}.git"
NVM_SOURCE_URL="https://gitcode.net/mirrors/${NVM_GITHUB_REPO}.git"
export NVM_NODEJS_ORG_MIRROR="https://npm.taobao.org/mirrors/node"
export NVM_IOJS_ORG_MIRROR="https://npm.taobao.org/mirrors/iojs
vi ~/.profile
source ~/.bashrc
nvm -help
nvm list
nvm install stable
node -version
npm -verinon
npm install -g nrm --registry=https://registry.npmmirror.com
nrm --version
nrm -help
nrm use cnpm
mkdir my-electron-app && cd my-electron-app
npm init
npm install --save-dev electron
npm start
npm install -g yarn
yarn add electron-builder --dev
./node_modules/.bin/electron-builder
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
main.js 内容
const { app, BrowserWindow } = require('electron')
const path = require('path')
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
win.loadURL('https://www.bilibili.com/')
win.on('closed', () => { app.quit() })
}
app.whenReady().then(() => { createWindow() })
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
运行效果
electron-builder打包前修改package.json
"build": {
"mac": {
"target": [
{
"target": "dmg",
"arch": [
"x64",
"arm64"
]
},
{
"target": "zip",
"arch": [
"x64",
"arm64"
]
}
]
},
"win": {
"target": [
{
"target": "nsis",
"arch": [
"x64",
"ia32"
]
},
{
"target": "zip",
"arch": [
"x64",
"ia32"
]
}
]
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38