上篇文章基本上能解决80%electron+node打包遇到的问题:https://www.cnblogs.com/mdorg/p/10417945.html,

大家能看到的基本上是版本号,但是abi到底是个什么玩意?怎么获取成为一个问题。

这里提供一个abi与target转换的小demo,仅供参照:

npm中有个node-abi的第三方库,把这个引用到你的electron代码中,如这样:

const nodeAbi = require(‘node-abi’);

在package.json中配置如下:

在渲染程序中的应用:

  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="UTF-8">
  6. <title>Hello Electron!</title>
  7. </head>
  8.  
  9. <body>
  10. <h3>
  11. <select id="sel_val">
  12. <option value="node" select='select'>node</option>
  13. <option value="electron">electron</option>
  14. </select>
  15. <input type="text" id="txt_val">
  16. <button type="button" onclick="getAbi()">GetABI</button>
  17. <button type="button" onclick="getTarget()">GetTarget</button>
  18. <div>
  19. ABI:<span id="span_abi_val"></span>
  20. TARGET:<span id="span_target_val"></span>
  21. </div>
  22. <div id="error" style="color:red"></div>
  23. </h3>
  24.  
  25. <script>
  26. const nodeAbi = require('node-abi');
  27. const error = document.getElementById('error');
  28. const sel = document.getElementById('sel_val');
  29. const txt = document.getElementById("txt_val");
  30. function getAbi(){
  31. try{
  32. error.innerHTML = "";
  33. const val = nodeAbi.getAbi(txt.value, sel.value);
  34. document.getElementById('span_abi_val').innerHTML = val;
  35. }
  36. catch(ex){
  37. error.innerHTML = ex.message
  38. }
  39. }
  40. function getTarget(){
  41. try{
  42. error.innerHTML = "";
  43. const val = nodeAbi.getTarget(txt.value, sel.value)
  44. document.getElementById('span_target_val').innerHTML = val;
  45. }
  46. catch(ex){
  47. error.innerHTML = ex.message
  48. }
  49. }
  50. </script>
  51. </body>
  52.  
  53. </html>

 具体效果如下:

 

 

 如果你当前的使用的node版本是10.15.0,那么abi是多少呢?

 

那么electron中的abi为64的版本号是多少呢?

这样在electron+node开发项目时,就可以选择abi一致的版本,这样可以避免不少问题。

 

此问题就先这样,希望对你有所帮助!

版权声明:本文为mdorg原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/mdorg/p/10419506.html