我正在构建和运行一个Angular 8 / Electron 5桌面应用程序。在我认为已经正确设置之后,运行该应用程序会显示一个空白的白屏。
使用:
Electron 5.0.2
Angular CLI 8.0.1
Node 10.16.0
macOS Mojave 10.14.5
...
ng new my-app
npm i -D electron
package.json
{
...
"main": "main.js", //<-- ADDED
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "ng build --baseHref=./ && electron ." //<-- ADDED
}
...
}
主程序.js
const { app, BrowserWindow } = require("electron");
const path = require("path");
const url = require("url");
let win;
function createWindow() {
win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL(
url.format({
pathname: path.join(__dirname, `/dist/index.html`), //<-- CHANGED
protocol: "file:",
slashes: true
})
);
win.on("closed", () => {
win = null;
});
}
app.on("ready", createWindow);
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
app.on("activate", () => {
if (win === null) {
createWindow();
}
});
我还在angular.json中将outputPath更改为"dist"
{
...
"outputPath": "dist"
...
}
使用npm run electron
启动应用程序。
当应用程序打开时,我看到一个空白的白屏。经检查,我可以看到文档主体和<app-root>
元素,但是页面上只有一个空白的白屏。
在CLI中执行ng new my-app
时,我尝试了启用和禁用路由标志。
在Electron应用程序控制台中,在Electron安全警告之前出现以下错误:
runtime-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
styles-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
main-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
polyfills-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
vendor-es2015.js:1 Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.