修改打包为exe单文件

This commit is contained in:
Soviby 2024-09-23 00:26:29 +08:00
parent 11b539eb56
commit 89440a531a
6 changed files with 24 additions and 14 deletions

View File

@ -18,7 +18,7 @@
"@vitejs/plugin-vue": "^5.0.5", "@vitejs/plugin-vue": "^5.0.5",
"@vue/tsconfig": "^0.5.1", "@vue/tsconfig": "^0.5.1",
"electron": "^25.3.0", "electron": "^25.3.0",
"electron-builder": "^24.4.0", "electron-builder": "latest",
"npm-run-all2": "^6.2.0", "npm-run-all2": "^6.2.0",
"typescript": "~5.4.0", "typescript": "~5.4.0",
"vite": "^5.3.1", "vite": "^5.3.1",

View File

@ -31,21 +31,30 @@ export const ElectronBuildPlugin = (): Plugin => {
fs.mkdirSync('dist/node_modules') fs.mkdirSync('dist/node_modules')
electronBuilder.build({ electronBuilder.build({
config:{ config:{ // 通常是文件 electron-builder.yml
directories: { directories: {
output: path.resolve(process.cwd(), 'release'), output: path.resolve(process.cwd(), 'release'),
app: path.resolve(process.cwd(), 'dist'), app: path.resolve(process.cwd(), 'dist'),
}, },
asar: true, appId: 'com.c1.game.launcher',
appId: 'com.example.app', productName: 'c1-game-launcher',
productName: 'vite-electron', win: {
nsis:{ icon: path.resolve(process.cwd(), 'src/assets/test-icon.ico'), // 指定图标文件路径
oneClick: false, // 取消一键安装 target: [
allowToChangeInstallationDirectory: true, // 允许用户选择安装目录 {
target: 'portable',
arch: ['x64', 'ia32']
}
]
} }
} }
}) })
.then(() => {
console.log('Build successful!')
})
.catch((error) => {
console.error('Error during build:', error)
})
} }
} }
} }

View File

@ -31,13 +31,14 @@ export const ElectronDevPlugin = (): Plugin => {
const IP = `http://localhost:${addressInfo.port}` const IP = `http://localhost:${addressInfo.port}`
// 进程传参发给electron IP地址 // 进程传参发给electron IP地址
let ElectronProcess = spawn(require('electron'), ['dist/background.js', IP]) let electronProcess = spawn(require('electron'), ['dist/background.js', IP])
fs.watchFile('src/background.ts', ()=>{ fs.watchFile('src/background.ts', ()=>{
ElectronProcess.kill() console.log('提示', 'background.ts 文件发生改变electronProcess 重新启动')
electronProcess.kill()
BuildBackground() BuildBackground()
ElectronProcess = spawn(require('electron'), ['dist/background.js', IP]) electronProcess = spawn(require('electron'), ['dist/background.js', IP])
}) })
ElectronProcess.stderr.on('data', (data) => { electronProcess.stderr.on('data', (data) => {
console.log('日志', data.toString()) console.log('日志', data.toString())
}) })

View File

@ -5,6 +5,7 @@ import TheWelcome from './components/TheWelcome.vue'
<template> <template>
<header> <header>
<h1> Hello Soviby! </h1>
<img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" /> <img alt="Vue logo" class="logo" src="./assets/logo.svg" width="125" height="125" />
<div class="wrapper"> <div class="wrapper">

BIN
src/assets/test-icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 KiB

View File

@ -13,7 +13,6 @@ app.whenReady().then(()=>{
}) })
// win.webContents.openDevTools() // 开发环境打开控制台 // win.webContents.openDevTools() // 开发环境打开控制台
if(process.argv[2]) // 开发环境 if(process.argv[2]) // 开发环境
{ {
win.loadURL(process.argv[2]) win.loadURL(process.argv[2])