Mac环境安装Electron

Electron

Electron简介

使用 JavaScript, HTML 和 CSS 构建跨平台的桌面应用。

Electron安装

1. 官网安装指南

2. 使用cnpm安装

国内使用npm安装Electron会报错,所以使用cnmp安装Electron

  • 安装npm:brew install node
  • 安装cnpm:npm install -g cnpm --registry=https://registry.npm.taobao.org
  • 安装Electron:npm install electron -g

Electron快速入门

示例1:使用官网的electron-quick-start作为例子

# 克隆这仓库
$ git clone https://github.com/electron/electron-quick-start
# 进入仓库
$ cd electron-quick-start
# 安装依赖库
$ npm install
# 运行应用
$ npm start

示例2:使用全局依赖库

# 克隆这仓库
$ git clone https://github.com/electron/electron-quick-start
# 进入仓库
$ cd electron-quick-start
# 运行应用
$ npm start

使用Visual Studio Code开发

配置VS Code

配置一:针对示例1中,每个项目都有自己单独的依赖库,而不是使用全局依赖库的情况

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Electron Main",
            "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
            "program": "${workspaceFolder}/main.js",
            "protocol": "legacy"
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/main.js"
        }
    ]
}

配置二:针对示例2,使用全局依赖库的情况

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Electron Main",
        "runtimeExecutable": "/usr/local/bin/electron",
        "program": "${workspaceFolder}/main.js",
        "protocol": "legacy"
    },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/main.js"
        }
    ]
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。