简体   繁体   English

由system.js加载脚本时如何要求('electron')

[英]How to require('electron') when script is loaded by system.js

I'm trying to use Aurelia and SystemJs within an electron app; 我正在尝试在电子应用程序中使用Aurelia和SystemJ;

I have a fairly basic app-window.js : 我有一个相当基本的app-window.js

const remote = require('electron').remote;

document.getElementById("close-btn").addEventListener("click", function (e) {
  var window = remote.getCurrentWindow();
  window.close();
});

...

if I consume it as normal html script ( <script src="app-window.js"></script> ) it works perfectly fine. 如果我将其用作普通的html脚本( <script src="app-window.js"></script> ),则可以正常工作。

However, if I have systemJS import it: 但是,如果我有systemJS导入它:

<script>
    System.import('app-window.js');
</script>

I get the error: 我得到错误:

system.js:4 GET file:///D:/Code/aurelia-electron-typescript/output/electron.js net::ERR_FILE_NOT_FOUND system.js:4 GET文件:/// D:/Code/aurelia-electron-typescript/output/electron.js net :: ERR_FILE_NOT_FOUND

Also I have transpiler: false set in the config too. 另外我也有transpiler: false也在配置中设置。

Unfortunately I would like to have my cake and eat it as I'd like to mingle Aurelia's dependency injection with electron's remoting features. 不幸的是,我想吃点蛋糕,因为我想将Aurelia的依赖注入与电子远程处理功能相结合。

Is there a way to have system.js not meddle with electron's require ? 有没有办法让system.js不与电子require混为一谈?

After a quick experiment... it would appear if the script explicitly loads up with System, it magically works: 经过快速实验...如果脚本显式加载了System,就会出现,它神奇地起作用了:

typescript: 打字稿:

export class AppWindow
{  
  constructor()
  {
    var remote = require('electron').remote;

    document.getElementById("close-btn").addEventListener("click", function (e) {
      var window: Electron.BrowserWindow = remote.getCurrentWindow();
      window.close();
    });
  }
}
var appWindow:AppWindow = new AppWindow()

which when compiled to [es6, System]: 编译为[es6,System]时:

System.register([], function(exports_1, context_1) {
    "use strict";
    var __moduleName = context_1 && context_1.id;
    var AppWindow, appWindow;
    return {
        setters:[],
        execute: function() {
            class AppWindow {
                constructor() {
                    var remote = require('electron').remote;
    ...

...works perfectly fine. ...工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM