1、先創(chuàng)建一個項目文件夾(例如:first_electron)
2、通過終端進入到這個文件夾
3、執(zhí)行npm init 初始化一個 npm 包 (就一直回車就創(chuàng)建完了)
4、箭頭指的這兩個內(nèi)容填上 一個是開發(fā)者 一個是簡介

image.png
5、初始化包并安裝 Electron (最坑的一步)
執(zhí)行下面命令
npm install electron --save-dev如果正常執(zhí)行 下面就不用看了
如果卡主不動的話就需要下面操作(因為安裝了vscode 所以就在這里面打開)
1:確認 code 命令可用
在終端里輸入:code -v
如果提示 command not found,說明沒配置 VS Code 的命令行。
?? 解決:
打開 VS Code
按 Command + Shift + P(Mac)調(diào)出命令面板
輸入并執(zhí)行:Shell Command: Install 'code' command in PATH
關(guān)掉終端,重新打開,再試:code -v
有輸出日志的話
下面在執(zhí)行 npm config set editor "code --wait" 設(shè)置 npm 的默認編輯器VS Code
后面再執(zhí)行 npm config edit 打開配置頁面

image.png
找一下有沒有這三個配置 有的話就替換=號后面的內(nèi)容,沒有的話就添加一下
electron_builder_binaries_mirror=https://npmmirror.com/mirrors/electron-builder-binaries/
electron_mirror=https://cdn.npmmirror.com/binaries/electron/
registry=https://registry.npmmirror.com
刪除你項目的node_modules文件夾(如果有的話,沒有就不用管了)
先關(guān)閉終端再重新打開(穩(wěn)妥一點)
執(zhí)行命令清除npm的緩存npm cache clean --force
之后再執(zhí)行npm install electron --save-dev就能正常了
剩下的就根據(jù)官方文檔一步一步往下面操作就可以了