Import node modules with electronic and system

I just wondered if systemjs require ("remote") could be used. require ("nodemodule") if the js system cannot find the module in its own registry?

I think something like this mechanism already works when using an electron with typescript and commonjs modules ...

Has anyone already decided this fight?

+5
source share
1 answer

Finally, after a while 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"); 

Just add all the imported node_modules to the array and everything will be fine

+1
source

All Articles