3 回答

TA貢獻1807條經驗 獲得超9個贊
這是因為您正在使用 ,這是預期的行為。concurrently
當您關閉窗口(并在macOS上退出程序)時,電子過程確實會停止,但是您在終端中發出的命令仍在運行,因為您仍在運行 。react-scripts
查看腳本,您說要運行命令和 .當您關閉電子應用程序時,它會告訴您該過程已結束()。但是,您只結束了您創建的 2 個進程中的 1 個。創建的進程仍在運行,因此終端控制權不會返回給您。electron-dev
npm start
wait-on http://localhost:3000 && electron .\
wait-on http://localhost:3000 && electron . exited with code 0
npm start
npm start
執行命令 ,該命令設置開發環境并啟動服務器。您有幾個選項可以殺死該過程,CTRL + C是其中最簡單的。react-scripts start
打包應用程序時,您不會遇到此問題,當用戶關閉窗口(或在macOS上退出程序)時,應用程序將完全關閉

TA貢獻1875條經驗 獲得超5個贊
解決此問題的最優雅方法是在腳本中使用 / 選項。--kill-others-kconcurrently
在我的包文件中,在腳本下:
"dev": "concurrently \"npm run client\" \"wait-on tcp:3000 && electron .\" -k",
在相關進程的任何類型的退出中,其他進程也將停止。這可以由 進一步控制,如其文檔中所述:--kill-others-on-fail
https://www.npmjs.com/package/concurrently
Killing other processes
-k, --kill-others kill other processes if one exits or dies [boolean]
--kill-others-on-fail kill other processes if one exits with non zero
status code [boolean]
添加回答
舉報