我正在构建和运行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
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
}
...
}
Run Code Online (Sandbox Code Playgroud)
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();
}
});
Run Code Online (Sandbox Code Playgroud)
我还将angular.json中的outputPath 更改为“ dist”
{
...
"outputPath": "dist"
...
}
Run Code Online (Sandbox Code Playgroud)
启动应用程序 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.
Run Code Online (Sandbox Code Playgroud)
R. *_*rds 22
I got my electron application to work by changing the target in the tsconfig.json to 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"
]
}
}
Run Code Online (Sandbox Code Playgroud)
Prior to this, I was getting the blank (white) screen too after updating the Angular 8. Seems now that Angular does a build in both es5 and es2015, electron doesn't like that. I would guess this will be fixed in the future.
UPDATE 2019-10-24:
Looks like this was fixed in electron@7.0.0. You can target es2015 with that version. Tested with @angular/cli@8.3.14.
| 归档时间: |
|
| 查看次数: |
2875 次 |
| 最近记录: |