1. 程式人生 > >Slog61_NodejsGUI之Electron模組的安裝和測試

Slog61_NodejsGUI之Electron模組的安裝和測試

  • ArthurSlog
  • SLog-61
  • Year·1

  • Guangzhou·China

  • Sep 6th 2018

關注微信公眾號“ArthurSlog”

不言之教 無為之益 天下希及之

開發環境MacOS(High Sierra 10.13.5)

需要的資訊和資訊源:

開始編碼

  • 新建一個資料夾 electron_learningload,然後切換至electron_learningload路徑下

cd ~/Desktop/

mkdir electron_learningload && cd electron_learningload

  • 使用npm初始化環境(其實就是建立並配置一個package.json檔案)

sudo npm init

  • 然後使用npm安裝 electron 開發工具包,根據electron官方說明
To install prebuilt Electron binaries, use npm. The preferred method is to install Electron as a development dependency in your app:

npm install electron --save-dev
  • 根據以上,我們使用npm執行一下指令,安裝 electron modules

npm install electron –save-dev

  • 結果是報錯,錯誤資訊如下
Error: EACCES: permission denied

......
  • ok,這裡出現了 EACCES 錯誤事件,提示許可權問題

sudo npm install electron –save-dev –unsafe-perm=true

  • ok,現在 electron 模組應該安裝成功了

  • 寫個指令碼來驗證一下

~/Desktop/electron_learningload/index.js

const electron = require('electron')
const proc = require('child_process'
) console.log(electron) const child = proc.spawn(electron)
  • 現在切換至檔案路徑下

cd ~/Desktop/electron_learningload/

  • 執行指令碼

node index.js

  • 正常執行下,會開啟一個Electron GUI介面

  • 至此,我們完成了Nodejs第三方模組Electron的安裝和測試。

歡迎關注我的微信公眾號 ArthurSlog

關注微信公眾號“ArthurSlog”

如果你喜歡我的文章 歡迎點贊 留言

謝謝