ubuntu16配置Electron环境

一、什么是 Electron

概述:

Electron 前称为atom shell,是从github开源项目Atom编辑器中抽离出来的,是一个能让你通过 JavaScriptHTML 和 CSS 构建桌面应用的 。这些应用能打包到 Mac、Windows 和 Linux 电脑上运行。

组成:

Electron 结合了 ChromiumNode.js和用于调用3个操作系统本地功能的API(如打开文件窗口、通知、图标等): 


  • Chromium:Google 创造的一个开源库,并用于 Google 的浏览器 Chrome;
  • Node.js(Node):一个用于在服务器运行JavaScript的工具,拥有文件系统和网络的权限;
  • Native API:支持3个操作系统(Windows、Mac和Linux)的原生API库。

开发体验:

跟网页开发很相似,通过HTML和CSS搭建界面,使用Node(JavaScript)编写逻辑,就像开发一个Node应用


二、安装Node.js Electron

sudo apt-get install curl

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

sudo apt-get install -y nodejs

sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

sudo cnpm install -g electron

或者

sudo add-apt-repository ppa:chris-lea/node.js

sudo apt-get update

sudo apt-get install nodejs

sudo apt install nodejs-legacy

sudo apt install npm

sudo npm config set registry https://registry.npm.taobao.org

sudo npm config list

sudo npm install n -g

sudo n stable

sudo node -v

sudo npm install --unsafe-perm -g electron

github上提供了一个简单的案例:electron-quick-start 

根据官方引导,使用以下指令:

# Clone this repository

git clone https://github.com/electron/electron-quick-start

# Go into the repository

cd electron-quick-start

# Install dependencies

cnpm install

# Run the app

cnpm start
 
  
 
 


执行正常会弹出Helloworld窗口:





猜你喜欢

转载自blog.csdn.net/a18373279153/article/details/80708763