当使用Electron builder构建时,Electron应用程序显示空白屏幕

当使用Electron builder构建时,Electron应用程序显示空白屏幕,electron,electron-builder,Electron,Electron Builder,正如标题所解释的,我有一个简单的Electron应用程序,在启动时加载html页面。一切正常,但如果我尝试使用electron builder(Thread dist)构建项目,应用程序只会显示一个空白屏幕。你知道为什么会这样吗 我的项目结构如下: -- e2e -- dist -- node_modules -- src -- app -- assets -- environments -- index.html -- editor.config -- angular.

正如标题所解释的,我有一个简单的Electron应用程序,在启动时加载html页面。一切正常,但如果我尝试使用electron builder(
Thread dist
)构建项目,应用程序只会显示一个空白屏幕。你知道为什么会这样吗

我的项目结构如下:

-- e2e
-- dist
-- node_modules
-- src
   -- app
   -- assets
   -- environments
   -- index.html
-- editor.config
-- angular.json
-- broswerlist
-- karma.conf.js
-- main.js
-- package.json
-- package-lock.json
-- tsconfig.json
-- tslint.json
我还发布了我的
main.js
package.json
文件:

main.js

const electron = require("electron")
const {app, Menu, BrowserWindow} = require("electron")
const path = require("path")

let mainWindow

app.on('window-all-closed', e => e.preventDefault() )
app.on('ready', createWindow);

function createWindow() {

  mainWindow = new BrowserWindow({
    width:1380,
    frame:false,
    closable: false,
    minimizable: false,
    maximizable: false,
    resizable: false,
    autoHideMenuBar: true,
    webPreferences: {
      nodeIntegration: true
    }
  })


  mainWindow.webContents.openDevTools();


  mainWindow.loadURL(url.format({
    pathname: path.join(__dirname, 'dist/index.html'),
    protocol: "file",
    slashes: "true"
  }))

}
package.json

{
  "name": "test_app",
  "version": "1.0.0",
  "description": "test",
  "author": "me",
  "main": "main.js",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "electron": "electron .",
    "dist": "electron-builder",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "devDependencies": {
    "electron": "7.1.8",
    "electron-builder": "^22.2.0"
  },
  "build": {
    "target": [
      "nsis"
    ]
  },
  "dependencies": {
    "msal-electron-poc": "^0.1.0",
    "@angular-devkit/build-angular": "~0.803.21",
    "@angular/animations": "~8.2.14",
    "@angular/cli": "~8.3.21",
    "@angular/common": "~8.2.14",
    "@angular/compiler": "~8.2.14",
    "@angular/compiler-cli": "~8.2.14",
    "@angular/core": "~8.2.14",
    "@angular/forms": "~8.2.14",
    "@angular/language-service": "~8.2.14",
    "@angular/platform-browser": "~8.2.14",
    "@angular/platform-browser-dynamic": "~8.2.14",
    "@angular/router": "~8.2.14",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "fs": "0.0.1-security",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "rxjs": "~6.4.0",
    "ts-node": "~7.0.0",
    "tslib": "^1.10.0",
    "tslint": "~5.15.0",
    "typescript": "~3.5.3",
    "zone.js": "~0.9.1"
  }
}

我也有同样的问题。并且能够在windows上运行electron。 对于windows:

vue-cli-service electron:build --mode development --windows
对于Linux:

vue-cli-service electron:build --mode development --rpm

然后检查是否有一些隐藏的错误,或者它只是在之后工作。

也有同样的问题。并且能够在windows上运行electron。 对于windows:

vue-cli-service electron:build --mode development --windows
对于Linux:

vue-cli-service electron:build --mode development --rpm

然后检查是否有一些隐藏的错误或它只是在之后工作。

path.join(\uu dirname,'dist/index.html')的值是否与您期望的匹配?我实际上不知道。我正在尝试加载angular创建并由electron builder打包的html文件,但我不知道它的位置,也无法浏览它,因为它位于asar文件中。您可以使用来浏览asar文件,但我认为您需要
path.join(\uu dirname,'dist/which your app name是/index.html')
是否设置
path.join的值(uu dirname,'dist/index.html')
符合您的期望?我实际上不知道。我正在尝试加载angular创建并由electron builder打包的html文件,但我不知道它的位置,我无法浏览它,因为它位于asar文件中。您可以使用来浏览asar文件,但我认为您需要
path.join(uu dirname,'dist/无论你的应用程序名是什么/index.html')
这不是应该在angular组件不工作的情况下加载源html文件吗?对于Electron builder,dist是应用程序文件出现的文件夹,它被排除在构建之外。在您的情况下,在通过angular CLI编译源代码后,使用其他名称代替dist。这不是应该加载源代码吗没有angular组件工作的html文件?对于Electron builder,dist是应用程序文件出现的文件夹,它被排除在构建之外。对于您的情况,在通过angular CLI编译源代码后,使用其他名称代替dist。