electron 和 serialport 項目整合(編譯打包成安裝包全流程)
項目地址: https://github.com/han-guang-xue/electronSerialport
應用到的主要點:
1.打包使用 electron-builder 配置的打包
2.electron不同的版本與serialport打包可能會產生不同的問題
碰見的問題:
1. 在使用 electron-rebuild 重新編譯之后開發環境中是正常使用,但是 electron-build 打包之后,串口連接返回錯誤狀態碼(electron 版本是 9.0.5)
解決方案: 替換 electron 版本為 11.1.0
2. 替換 electron 版本為 11.1.0 之后, 直接使用 electron-builder 編譯打包, 串口接口使用報錯; 報錯信息:
TypeError: Third argument must be a function at internal/util.js:297:30 at new Promise (<anonymous>) at open (internal/util.js:296:12) at WindowsBinding.open (C:\Program Files\client\resources\app\node_modules\serialport\node_modules\@serialport\bindings\lib\win32.js:56:22) at processTicksAndRejections (internal/process/task_queues.js:97:5)
解決方案: 在 package.json 中的 build 中配置 `"buildDependenciesFromSource":true,`
項目地址: https://github.com/han-guang-xue/electronSerialport/blob/main/README.md
