ai处理打包后白屏的问题
This commit is contained in:
parent
7e8c417c48
commit
6a81060e77
@ -1,5 +1,6 @@
|
||||
// 确保所有导入都使用 ES 模块语法
|
||||
import { app, BrowserWindow, ipcMain, dialog } from "electron";
|
||||
import { fs } from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { migrateDatabases } from './db/migration.js';
|
||||
@ -82,6 +83,7 @@ function createWindow() {
|
||||
preload: path.join(__dirname, "../electron/preload.js"),
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
openDevTools: true,
|
||||
},
|
||||
});
|
||||
|
||||
@ -110,32 +112,30 @@ function createWindow() {
|
||||
// 检查哪个路径存在
|
||||
for (const pathOption of pathsToTry) {
|
||||
console.log(`尝试检查路径: ${pathOption}`);
|
||||
try {
|
||||
if (fs.existsSync(pathOption)) {
|
||||
indexPath = pathOption;
|
||||
console.log(`找到文件: ${indexPath}`);
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`检查路径时出错: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (indexPath) {
|
||||
try {
|
||||
// 使用file://协议加载本地文件,避免路径问题
|
||||
mainWindow.loadFile(indexPath);
|
||||
// 添加加载完成事件监听
|
||||
mainWindow.webContents.on('did-finish-load', () => {
|
||||
console.log('文件加载完成');
|
||||
// 显示开发者工具便于调试
|
||||
mainWindow.webContents.openDevTools();
|
||||
});
|
||||
// 添加加载失败事件监听
|
||||
mainWindow.webContents.on('did-fail-load', (event, errorCode, errorDescription) => {
|
||||
console.error(`文件加载失败: ${errorCode} - ${errorDescription}`);
|
||||
dialog.showErrorBox('加载失败', `无法加载应用界面: ${errorDescription}`);
|
||||
});
|
||||
// 添加页面崩溃事件监听
|
||||
mainWindow.webContents.on('crashed', (event, killed) => {
|
||||
console.error(`页面崩溃: ${killed ? '被杀死' : '意外崩溃'}`);
|
||||
dialog.showErrorBox('页面崩溃', `应用界面崩溃: ${killed ? '被杀死' : '意外崩溃'}`);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`加载文件时出错: ${error}`);
|
||||
dialog.showErrorBox('加载失败', `无法加载应用界面: ${error.message}`);
|
||||
@ -146,6 +146,7 @@ function createWindow() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 添加窗口关闭前的确认对话框
|
||||
mainWindow.on('close', (event) => {
|
||||
// 阻止默认关闭行为
|
||||
|
@ -1,4 +1,4 @@
|
||||
// 将导入createWebHistory改为createWebHashHistory
|
||||
// 确保使用createWebHashHistory
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import WelcomeView from '@/views/WelcomeView.vue'
|
||||
import ExamingView from '@/views/user/ExamingView.vue'
|
||||
|
@ -2,10 +2,11 @@ import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
import electron from 'vite-plugin-electron'
|
||||
// 只保留一个 fileURLToPath 导入
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
export default defineConfig({
|
||||
// 添加base配置,确保静态资源使用相对路径
|
||||
base: './',
|
||||
plugins: [
|
||||
vue(),
|
||||
vueDevTools(),
|
||||
@ -22,4 +23,14 @@ export default defineConfig({
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
},
|
||||
},
|
||||
build: {
|
||||
// 确保打包后的文件使用相对路径
|
||||
rollupOptions: {
|
||||
output: {
|
||||
assetFileNames: 'assets/[name]-[hash].[ext]',
|
||||
chunkFileNames: 'chunks/[name]-[hash].js',
|
||||
entryFileNames: 'entry-[name]-[hash].js',
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user