Electron如何调用NodeJS扩展模块

xiaoxiao2021-02-28  71

如何准备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

转载请注明原文地址: https://www.6miu.com/read-64041.html

最新回复(0)