由system.js加载脚本时如何要求('electron') [英] How to require('electron') when script is loaded by system.js
问题描述
我正在尝试在电子应用程序中使用Aurelia和SystemJ;
I'm trying to use Aurelia and SystemJs within an electron app;
我有一个相当基本的app-window.js
:
const remote = require('electron').remote;
document.getElementById("close-btn").addEventListener("click", function (e) {
var window = remote.getCurrentWindow();
window.close();
});
...
如果我将其作为普通的html脚本(<script src="app-window.js"></script>
)使用,则可以正常工作.
if I consume it as normal html script (<script src="app-window.js"></script>
) it works perfectly fine.
但是,如果我有systemJS
导入它:
However, if I have systemJS
import it:
<script>
System.import('app-window.js');
</script>
我得到了错误:
system.js:4 GET 文件:///D:/Code/aurelia-electron-typescript/output/electron.js 净:: ERR_FILE_NOT_FOUND
system.js:4 GET file:///D:/Code/aurelia-electron-typescript/output/electron.js net::ERR_FILE_NOT_FOUND
我也在配置中也设置了transpiler: false
.
Also I have transpiler: false
set in the config too.
不幸的是,我想吃蛋糕并吃掉它,因为我想将Aurelia的依赖注入与电子的远程处理功能混合在一起.
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.
有没有办法让system.js不与电子的require
混在一起?
Is there a way to have system.js not meddle with electron's require
?
推荐答案
快速实验之后……如果脚本明确加载了System,它就会神奇地起作用:
After a quick experiment... it would appear if the script explicitly loads up with System, it magically works:
打字稿:
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()
编译为[es6,System]时:
which when compiled to [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;
...
...工作正常.
这篇关于由system.js加载脚本时如何要求('electron')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!