窗口在构建时不呈现,在开发服务器中工作正常
Posted
技术标签:
【中文标题】窗口在构建时不呈现,在开发服务器中工作正常【英文标题】:Window does not render on build, works fine in development server 【发布时间】:2021-01-25 03:52:28 【问题描述】:我的应用在构建时不显示窗口,但在我运行 npm run serve
时工作正常
任务管理器中仍然有一个进程在运行,如果我使用安装程序也会发生同样的事情。我没有收到来自 electron-builder 的任何错误警告。
background.js:
import app, protocol, dialog, BrowserWindow, ipcMain, shell from 'electron'
import createProtocol from 'vue-cli-plugin-electron-builder/lib'
import installExtension, VUEJS_DEVTOOLS from 'electron-devtools-installer'
import path from 'path'
import fs from 'fs'
import childProcess from 'child_process'
import ncp from 'ncp'
const isDevelopment = process.env.NODE_ENV !== 'production'
// 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
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
scheme: 'app', privileges: secure: true, standard: true
])
function createWindow ()
// Create the browser window.
win = new BrowserWindow(
width: 1200,
height: 600,
resizable: false,
maximizable: false,
frame: false,
webPreferences:
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
preload: path.join(__dirname, 'preload.js')
)
if (process.env.WEBPACK_DEV_SERVER_URL)
// Load the url of the dev server if in development mode
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools()
else
createProtocol('app')
// Load the index.html when not in development
win.loadURL(path.join(__dirname,'index.html'))
win.on('closed', () =>
win = null
)
// 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()
)
我尝试了修复 here 和 here 无济于事。
我正在使用电子-vue。如果您需要更多上下文,可以找到完整代码here
【问题讨论】:
【参考方案1】:问题最终出现在 app.on('ready')
函数中。在创建窗口后需要编写任何额外的代码,否则会出现问题。
【讨论】:
以上是关于窗口在构建时不呈现,在开发服务器中工作正常的主要内容,如果未能解决你的问题,请参考以下文章
Angular 6 - 为啥生产构建中缺少承载令牌? (在开发版本中工作正常)