我只是想知道是否有可能使systemjs使用require(“ remote”)。require(“ nodemodule”),如果system js在自己的注册表中找不到该模块?
我认为将电子与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添加到数组即可,一切都很好
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句