前言
要开发 Electron 应用,您需要安装 Node.js 运行环境和它的包管理器 npm。 我们推荐安装最新的长期支持 (LTS) 版本。
安装nvm
node.js的版本管理工具
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
安装最新的 LTS 版本的 Node.js
nvm install --lts
验证安装
node -v
npm -v
创建一个demo项目
mkdir my-electron-app && cd my-electron-app
npm init
会简单配置一下package.json中的字段,回车到结束
配置代理,在项目里安装electron
npm config set registry https://registry.npmmirror.com
npm install electron --save-dev
官方demo
创建main.js
console.log('Hello from Electron 👋')
修改package.json
{
"name": "my-electron-app",
"version": "1.0.0",
"description": "Hello World!",
"main": "main.js",
"scripts": {
"start": "electron .",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jane Doe",
"license": "MIT",
"devDependencies": {
"electron": "23.1.3"
}
}
Run!
npm run start
Hello from Electron 👋
mesa: for the --simplifycfg-sink-common option: may only occur zero or one times!
mesa: for the --global-isel-abort option: may only occur zero or one times!
mesa: for the --amdgpu-atomic-optimizations option: may only occur zero or one times!