【问题标题】:Need help importing Electron in Aurelia app需要帮助在 Aurelia 应用程序中导入 Electron
【发布时间】:2018-03-29 19:59:07
【问题描述】:

我正在使用骨架导航骨架打字稿之一。

我正在尝试导入 Electron.remote,以便可以从 JS 中关闭电子窗口。这就是我在 config.js 中的内容:

  paths: {
    "*": "dist/*",
    "github:*": "jspm_packages/github/*",
    "npm:*": "jspm_packages/npm/*",
    "node_modules:*": "node_modules/*"
  },
  map: {
    "electron": "node_modules:electron/index.js",
  }

在我的 JS 文件中我这样导入:

import * as electron  from 'electron';

但我收到有关在路径中找不到 fs.js 的错误:

Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:9000/dist/fs.js

有人可以帮助我解决这个问题吗?

【问题讨论】:

    标签: electron aurelia systemjs jspm


    【解决方案1】:

    取决于您选择的加载器/捆绑器策略

    electron 定义了节点 require()。 您想在启动依赖 AMD 的应用程序之前重新定义它需要

    https://github.com/electron/electron/issues/303

    TL;DR 您想将节点要求分配给另一个变量 window.node_require = require 然后删除原来的 delete require

    只有在此之后,您才能在应用中引用脚本 在您的应用程序中,您使用node_require() 加载节点模块

    这里是相关评论:supporting electron modules in aurelia

    【讨论】:

    • 我正在使用 gulp 和 systemjs,我会按照你的建议尝试。
    • 该代码应该在您将电子渲染器导航到应用程序外部的页面中
    • 成功了。首先,我输入我的 index.html 头,这是我的条目:<script type="text/javascript"> window.node_require = require; delete window.require; delete window.exports; delete window.module; </script>,然后我为 BrowserWindow 和我的 TS 文件中设置了nodeIntegration: truedeclare global { interface Window { node_require: any; } } const remote = window.node_require('electron').remote;
    • 别害羞。回答你的问题并接受它。我试图找到你的代码但失败了。你得到了它自己的(-;
    【解决方案2】:

    这就是我使用 JSPM 和 SystemJS 解决 Aurelia Skeleton Typescript 问题的方法:我输入了 index.html head 这是我的条目:

      <script type="text/javascript">
        window.node_require = require;
        delete window.require;
        delete window.exports;
        delete window.module;
      </script>
    

    然后我为 BrowserWindow 设置nodeIntegration: true

    在我的 TS 文件中:

    declare global {
      interface Window {
        node_require: any;
      }
    }
    
    var remote: any;
    
    if (typeof window.node_require == "function") {
      remote = window.node_require('electron').remote;
    }
    
      closeApp() {
        var window = remote.getCurrentWindow();
        window.close();
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多