在使用electron,接入腾讯云TRTC时遇到找不到.node文件的问题
can't open ***/**/trtc-electron-sdk.node
解决方案:
参考node-loader源码,自定义loader,将绝对地址转换为相对地址,如下:
// custom-node-loader.js
module.exports = function () {
let nodeUrl = JSON.stringify(this.resourcePath);
if (process.env.NODE_ENV === 'production') {
nodeUrl = '__dirname +' + JSON.stringify(this.resourcePath.replace(__dirname, ''));
}
return 'try {global.process.dlopen(module, ' + nodeUrl + '); } catch(e) {' +
"throw new Error('Cannot open ' + " + nodeUrl + " + ': ' + e);}";
};
webpcak配置loader
{
test: /\.node$/,
use: './custom-node-loader.js'
}