首页 > 解决方案 > 使用电子生成器构建后,Angular 电子应用程序未加载 index.html 时出现白屏且没有错误

问题描述

我有一个角度电子应用程序,在将它与电子生成器捆绑之前,它工作得非常好(开发环境)。捆绑后安装打开,白屏无误!!

package.json是我的项目的文件

{
  "name": "groceryee",
  "productName": "Groceryee",
  "authors": "seifou eddine",
  "description": "groceryee",
  "version": "9.3.1",
  "scripts": {
    "ng": "ng",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "start": "concurrently \"ng serve\" \"npm run electron\"",
    "electron": "electron ./src/electron.dev",
    "build-installer": "electron-builder"
  },
  "build": {
    "appId": "com.groceryee.webconcepter",
    "copyright": "Copyright © 2021 groceryee",
    "asar":false,
    "win": {
      "target": [
        "nsis"
      ],
      "requestedExecutionLevel": "requireAdministrator"
    },
    "nsis": {
      "oneClick": false,
      "allowToChangeInstallationDirectory": true,
      "uninstallDisplayName": "groceryee",
      "license": "license.txt"
    },
    "extraMetadata": {
      "main": "src/electron.prod.js"
    }
  }
  }

这是我electron.prod.js的项目文件

const { app, BrowserWindow } = require('electron');
const path = require('path');
const url = require('url');

// 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;

const createWindow = () => {
    // Create the browser window.
    win = new BrowserWindow({
        width: 800,
        height: 600,
        icon: path.join(__dirname, 'favicon.ico'),
    });

    // and load the index.html of the app.
    win.loadURL(url.format({
        pathname: path.join(__dirname, 'index.html'),
        protocol: 'file:',
        slashes: true
    }));
    win.webContents.openDevTools();
    // 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 macOS 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 macOS 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();
    }
});

我真的很困惑!我相信我所有的代码都是正确的,可能我忘记了什么

任何想法,请!

标签: electronelectron-builder

解决方案


推荐阅读