簡體   English   中英

使用electron和Systemjs導入節點模塊

[英]Importing node modules with electron and Systemjs

我只是想知道是否有可能使systemjs使用require(“remote”)。require(“nodemodule”),如果系統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添加到數組中即可

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM