angular - 全新 Angular 8/Electron 5 应用程序出现白屏
问题描述
我正在构建和运行 Angular 8/Electron 5 桌面应用程序。在我认为正确设置之后,运行该应用程序会显示一个空白屏幕。
使用:
电子 5.0.2
Angular CLI 8.0.1
节点 10.16.0
macOS Mojave 10.14.5
...
ng new my-app
npm i -D electron
包.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
}
...
}
main.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>
元素,但我在页面上看到的只是一个空白的白色屏幕。
这样做时,ng new my-app
我在 CLI 中尝试了使用和不使用路由启用标志。
在电子安全警告之前在电子应用程序控制台中获取这些错误:
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.
解决方案
我通过将tsconfig.jsontarget
中的更改为.es5
{
"compileOnSave": false,
"compilerOptions": {
"importHelpers": true,
"module": "esnext",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5", <-- HERE
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
在此之前,我在更新 Angular 8 后也遇到了空白(白色)屏幕。现在看来 Angular 确实在两者中进行了构建es5
,es2015
电子不喜欢那样。我想这将在未来得到解决。
2019 年 10 月 24 日更新:
看起来这是固定的electron@7.0.0
。您可以es2015
使用该版本进行定位。经测试@angular/cli@8.3.14
。
推荐阅读
- python - 如何在 df.loc[df.% Population < 2000] = 0 中转义字符
- sql - SQL~当值相同时如何按字母顺序排序
- r - 整理 - 使用 case_when 重新编码新变量不喜欢我的运算符
- python - 在测试 Django REST Framework 时,为什么我不能让 APIClient.credentials() 使用令牌进行身份验证?
- arrays - 如何将字典的键和值映射到 json 数组?
- c++ - 仅去除带有通配符排除的二进制文件的函数名称
- java - Kafka Java Producer 无法向 kafka 实例发送消息
- javascript - Array.prototype.forEach() json 数组
- hive - Teradata 转换为 hive sql 使用 case when
- c - 你如何防止输入在终端的新行上发送?