无法使用带有angular2和angular-cli的电子来查找供应商文件

nat*_*ate 2 javascript electron angular-cli angular

我使用angular-cli创建了一个示例英雄应用程序(快速启动中的应用程序),它按预期工作.

npm start 提出我的应用程序,按预期工作.

然而,在电子中启动应用程序似乎失败了.对于我的生活似乎无法弄清楚为什么电子无法找到其中包含的文件夹dist/.

即我的dist/目录有以下内容:

相当标准......

但是,当我启动electron dist/(包含index.js电子主文件)时,控制台输出以下内容:

Failed to load resource: net::ERR_FILE_NOT_FOUND
file:///vendor/systemjs/dist/system.src.js Failed to load resource: 
Run Code Online (Sandbox Code Playgroud)

但显然他们在vendor/目录中,因为我npm start的工作正常.

index.js几乎是入门的副本:

const electron = require('electron');
// Module to control application life.
const {app} = electron;
// Module to create native browser window.
const {BrowserWindow} = electron;

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win;

function createWindow() {
  // Create the browser window.
  win = new BrowserWindow({width: 800, height: 600});

  // and load the index.html of the app.
  win.loadURL(`file://${__dirname}/index.html`);


  // Emitted when the window is closed.
  win.on('closed', () => {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null;
  });
}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow);

// Quit when all windows are closed.
app.on('window-all-closed', () => {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform !== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (win === null) {
    createWindow();
  }
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
Run Code Online (Sandbox Code Playgroud)

小智 7

为了使您的应用程序能够使用file://协议,您需要执行以下操作:

在src/index.html内部,更改以下行,如下所示:

从:

<base href="/">
Run Code Online (Sandbox Code Playgroud)

<base href="./">
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.

编辑:另外,忘了提一下:如果您在线和离线运行您的应用程序,您可能想要使用某种检测,以便当应用程序在普通浏览器窗口内运行时,您可以切换回/ base,通过HTTP.