【问题标题】:Importing node modules with electron and Systemjs使用电子和 Systemjs 导入节点模块
【发布时间】:2016-03-23 14:08:29
【问题描述】:

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

我认为当将电子与 typescript 和 commonjs 模块一起使用时,这种机制已经开始工作了......

有人已经解决了这个难题吗?

【问题讨论】:

  • 看起来与我解决的同一问题 here.

标签: javascript node.js typescript electron systemjs


【解决方案1】:

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

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 添加到数组中就可以了

【讨论】:

    猜你喜欢
    • 2017-04-03
    • 2016-12-11
    • 1970-01-01
    • 2019-05-09
    • 2013-08-25
    • 2018-01-27
    • 2018-08-07
    • 1970-01-01
    相关资源
    最近更新 更多