本文介紹了使用電子和 Systemjs 導入節點模塊的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我只是想知道是否可以讓systemjs使用require(remote").require(nodemodule"),如果系統js在自己的注冊表中找不到模塊?
I just wondered if it is possible to make systemjs use require("remote").require("nodemodule"), if system js can't find the module in its own registry?
我認為當將電子與 typescript 和 commonjs 模塊一起使用時,這種機制已經在起作用了......
I think something like this mechanism is already working when using electron with typescript and commonjs modules...
有人已經解決了這個難題嗎?
Has someone already solved that struggle?
推薦答案
終于在一段時間后找到了一個可行的解決方案:
Finally after some time I found a working solution:
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 添加到數組中就可以了
Just add all imported node_modules to the array and things are fine
這篇關于使用電子和 Systemjs 導入節點模塊的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!