参考:
https://www.jianshu.com/p/cdb0f4249c88
https://www.jianshu.com/p/696fbdeb5b8a?from=timeline
https://www.w3cschool.cn/electronmanual/eqsc1qko.html
参考案例:
https://github.com/PowerDos/serialport_electron_start
编译原生模块:
npm install --save-dev electron-rebuild
# 每次运行"npm install"时,也运行这条命令
./node_modules/.bin/electron-rebuild
# 在windows下如果上述命令遇到了问题,尝试这个:
.\node_modules\.bin\electron-rebuild.cmd
如果报下图报错:
解决办法:
//16进制字符串转byte数组
function Str2Bytes(str){
var pos = 0;
var len = str.length;
if(len %2 != 0)
{
return null;
}
len /= 2;
var hexA = new Array();
for(var i=0; i<len; i++)
{
var s = str.substr(pos, 2);
var v = parseInt(s, 16);
hexA.push(v);
pos += 2;
}
return hexA;
}
版本:
打包:安装:
cnpm install -g electron-packager
package.json添加:
"package": "electron-packager ./ notes --all --out ./OutApp --arch=x64 --electron-version 4.0.8 --overwrite"
cmd运行:npm run package