gpt4 book ai didi

javascript - 使用 electron 和 Systemjs 导入 Node 模块

转载 作者:搜寻专家 更新时间:2023-10-30 20:44:06 24 4
gpt4 key购买 nike

我只是想知道是否可以让 systemjs 使用 require("remote").require("nodemodule"),如果 system js 在它自己的注册表中找不到模块?

我认为在将 electron 与 typescript 和 commonjs 模块一起使用时,类似这种机制的东西已经在起作用了......

有人已经解决了这场斗争吗?

最佳答案

终于在一段时间后我找到了一个可行的解决方案:

var node_modules = ["child_process","fs"];
var fetch = System.fetch;
window.remote=require("remote");
System.fetch = function () {
var promise= fetch.apply(System,arguments);
return promise.then(function (js) {
for(var m of node_modules){
var requireExpression = 'require("'+m+'");';
var remoteRequire = 'remote.require("'+m+'");'
js=js.replace(requireExpression,remoteRequire);
}
return js;
});
}
System.import("aurelia-bootstrapper");

只需将所有导入的 node_modules 添加到数组中就可以了

关于javascript - 使用 electron 和 Systemjs 导入 Node 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34328961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com