This commit is contained in:
chenqiang 2025-09-09 11:43:30 +08:00
parent f8723c204c
commit c2e30c5915
2 changed files with 36 additions and 45 deletions

View File

@ -1,6 +1,6 @@
const { execSync } = require('child_process');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const { execSync } = require('child_process'); // 确保导入execSync
// 创建一个兼容Node.js 12的删除文件夹函数 // 创建一个兼容Node.js 12的删除文件夹函数
function deleteFolderRecursive(dir) { function deleteFolderRecursive(dir) {
@ -49,7 +49,7 @@ function prepareForBuild() {
} }
} }
// 执行打包命令 - 移除临时修改package.json的逻辑 // 执行打包命令 - 简化命令行参数
function buildPortableApp() { function buildPortableApp() {
console.log('开始构建Windows 7便携应用...'); console.log('开始构建Windows 7便携应用...');
@ -58,9 +58,9 @@ function buildPortableApp() {
delete process.env.WIN_CSC_LINK; delete process.env.WIN_CSC_LINK;
delete process.env.WIN_CSC_KEY_PASSWORD; delete process.env.WIN_CSC_KEY_PASSWORD;
// 使用更明确的方式指定便携式构建 // 使用最基本的命令行参数让配置完全由vue.config.js控制
execSync( execSync(
'npm run electron:build -- --win --target portable --ia32 --x64 --publish never', 'npm run electron:build -- --win portable --ia32 --x64 --publish never',
{ stdio: 'inherit' } { stdio: 'inherit' }
); );

View File

@ -6,16 +6,21 @@ module.exports = {
return args; return args;
}); });
}, },
// 将outputDir移到顶层配置
// 输出目录
outputDir: 'dist_electron', outputDir: 'dist_electron',
pluginOptions: { pluginOptions: {
electronBuilder: { electronBuilder: {
// 基础配置
nodeIntegration: false, nodeIntegration: false,
contextIsolation: true, contextIsolation: true,
preload: "src/preload.js", preload: "src/preload.js",
mainProcessFile: "background/main.js", mainProcessFile: "background/main.js",
lintPreloadFiles: false, lintPreloadFiles: false,
externals: ["fontkit", "pdfkit"], externals: ["fontkit", "pdfkit"],
// 主进程webpack配置
chainWebpackMainProcess: (config) => { chainWebpackMainProcess: (config) => {
config.module config.module
.rule("babel") .rule("babel")
@ -39,59 +44,37 @@ module.exports = {
.end() .end()
.type("javascript/auto"); .type("javascript/auto");
}, },
// Windows 7便携应用配置 - 兼容Electron 11和electron-builder 22.9.1
win: { // 所有构建选项都放在这里
target: [
{
target: "portable",
arch: ["ia32", "x64"],
},
],
icon: "public/favicon.ico",
// 在electron-builder 22.9.1中compression选项应该在这里设置
// 删除了之前的错误配置
// 针对Windows 7的特殊配置
extraResources: [
{
from: "background", // 包含整个background目录
to: "background",
filter: ["**/*"],
},
{
from: "background/font",
to: "font",
filter: ["**/*"],
},
{
from: "data",
to: "data",
filter: [".gitignore"],
},
],
},
// 便携应用配置 - 兼容Electron 11
portable: {
artifactName: "统计技能考试系统_便携版_${version}_${arch}.exe",
// 启用便携模式标志
target: "portable",
},
// 在electron-builder 22.9.1中压缩配置应该在build选项中设置
builderOptions: { builderOptions: {
// 应用基本信息
appId: 'com.example.exam11',
productName: '统计技能考试系统',
// 压缩设置
compression: "store", compression: "store",
// 入口文件配置
extraMetadata: { extraMetadata: {
main: "background.js" main: "background.js"
}, },
// 将所有Windows配置统一到这里
// Windows构建配置
win: { win: {
// 架构设置
target: [ target: [
{ {
target: "portable", target: "portable",
arch: ["ia32", "x64"], arch: ["ia32", "x64"],
}, },
], ],
// 图标设置
icon: "public/favicon.ico", icon: "public/favicon.ico",
// 签名设置
signingHashAlgorithms: ['sha256'], signingHashAlgorithms: ['sha256'],
sign: false, // 明确禁用签名 sign: false, // 明确禁用签名
// 额外资源配置
extraResources: [ extraResources: [
{ {
from: "background", from: "background",
@ -110,10 +93,18 @@ module.exports = {
}, },
], ],
}, },
// portable配置 - 只保留artifactName
// 便携应用特定配置
portable: { portable: {
artifactName: "统计技能考试系统_便携版_${version}_${arch}.exe" artifactName: "统计技能考试系统_便携版_${version}_${arch}.exe",
// 只保留支持的属性移除target属性
}, },
// 发布设置
publish: {
provider: 'generic',
url: 'https://example.com/',
}
}, },
}, },
}, },