电子应用程序在使用电子生成器构建时显示空白屏幕

时间:2020-01-28 15:29:16

标签: electron electron-builder

正如标题所述,我有一个简单的Electron应用程序,该应用程序在启动时会加载html页面。一切正常,但是如果我尝试使用电子构建器(get)构建项目,则该应用程序只会显示空白屏幕。知道为什么会这样吗?

我的项目结构如下:

yarn 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文件:

main.js

package.json

package.json

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"
  }))

}

2 个答案:

答案 0 :(得分:0)

//Replace
path.join(__dirname, 'dist/index.html')

//with
path.join(__dirname, 'src/index.html')

答案 1 :(得分:0)

有同样的问题。并且能够通过运行在 Windows 上运行电子。 对于窗户:

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

对于 Linux:

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

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