欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

Electron如何调用NodeJS扩展模块

发布时间:2024/2/28 45 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Electron如何调用NodeJS扩展模块 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

如何准备Electron

http://blog.csdn.net/chenhaifeng2016/article/details/74917361


如何开发一个NodeJS第三方模块

http://blog.csdn.net/chenhaifeng2016/article/details/74939493


NodeJS第三方模块要用于Electron需要重新编译。

修改第三方模块的配置文件package.json

{"name": "facerecognitiondll","version": "1.0.0","description": "","main": "main.js","scripts": {"install": "node-gyp rebuild -target=1.6.11 -arch=x64 -dist-url=https://atom.io/download/atom-shell"},"author": "","license": "ISC","gypfile": true }
生成模块

npm install


创建文件main.js导出模块

const facerecognitiondll = require('./build/Release/facerecognitiondll');exports.CAMOpen = facerecognitiondll.CAMOpen;
通过npm install facerecognitiondll安装此模块到本地nodes_modules目录。


修改index.html

<!DOCTYPE html> <html> <head><meta charset="UTF-8"><title>人脸识别测试程序</title> </head> <body> <button id="CAMOpen" name="CAMOpen">调用人脸识别DLL</button> </body> <script>var addon = require("facerecognitiondll")document.write(addon.CAMOpen()) </script> </html>

运行npm start



项目结构



参考资料

https://github.com/electron/electron/blob/master/docs-translations/zh-CN/tutorial/using-native-node-modules.md

总结

以上是生活随笔为你收集整理的Electron如何调用NodeJS扩展模块的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。