gpt4 book ai didi

javascript - Window无法在构建中渲染,在开发服务器中可以正常工作

转载 作者:行者123 更新时间:2023-12-03 12:32:41 24 4
gpt4 key购买 nike

我的应用程序在构建时不显示窗口,但是在运行npm run serve时可以正常工作
任务管理器中仍在运行一个进程,如果我使用安装程序,也会发生相同的情况。我没有收到来自Electro-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()
}
})
我尝试修复 herehere无济于事。
我正在使用 Electron 战。如果需要更多上下文,可以找到完整的代码 here

最佳答案

问题最终是app.on('ready')函数内部存在代码。创建窗口或出现问题后,需要编写任何其他代码。

关于javascript - Window无法在构建中渲染,在开发服务器中可以正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64290655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com