src/background移至background

This commit is contained in:
chenqiang 2025-09-09 03:47:33 +08:00
parent cc9dd60a16
commit 5952c096f0
23 changed files with 8 additions and 35 deletions

View File

@ -49,41 +49,17 @@ function prepareForBuild() {
}
}
// 临时修改package.json的main字段
function updatePackageJson() {
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// 删除之前添加的临时修改package.json的逻辑因为现在路径已经正确
// 保存原始的main字段值
const originalMain = packageJson.main;
// 修改main字段为正确的路径
packageJson.main = 'src/background/main.js';
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('已临时修改package.json的main字段为: src/background/main.js');
// 返回恢复函数
return function restorePackageJson() {
packageJson.main = originalMain;
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('已恢复package.json的main字段为原始值');
};
}
// 执行打包命令
function buildPortableApp() {
console.log('开始构建Windows 7便携应用...');
// 临时修改package.json
const restorePackageJson = updatePackageJson();
try {
// 设置构建环境变量
process.env.WIN_CSC_LINK = '';
process.env.WIN_CSC_KEY_PASSWORD = '';
// 执行构建命令
// 执行构建命令 - 移除不兼容的--no-compress选项
execSync(
'npm run electron:build -- --win portable --ia32 --x64 --publish never',
{ stdio: 'inherit' }
@ -93,12 +69,7 @@ function buildPortableApp() {
console.log('构建产物位于 dist_electron 目录');
} catch (error) {
console.error('构建失败:', error);
// 确保即使构建失败也恢复package.json
restorePackageJson();
process.exit(1);
} finally {
// 无论构建成功与否都恢复package.json
restorePackageJson();
}
}

View File

@ -4,6 +4,7 @@
"private": true,
"description": "统计技能考试系统",
"author": "抚顺市统计局",
"main": "background/main.js",
"scripts": {
"start": "vue-cli-service electron:serve",
"serve": "vue-cli-service serve",
@ -16,7 +17,6 @@
"rebuild-deps": "electron-builder install-app-deps",
"rebuild-sqlite3": "npm_config_runtime=electron npm_config_target=11.5.0 npm_config_disturl=https://electronjs.org/headers npm_config_build_from_source=true node-pre-gyp rebuild --target=11.5.0 --runtime=electron --fallback-to-build --directory=./node_modules/sqlite3/ --dist-url=https://electronjs.org/headers"
},
"main": "background/main.js",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "1.2.36",
"@fortawesome/free-brands-svg-icons": "5.15.4",

View File

@ -246,7 +246,9 @@ export default {
}
).then(() => {
// store
this.$store.commit('clearExaminee')
this.$store.commit('clearUser') // mutation
//
this.$store.commit('clearPaper')
//
this.$router.push('/')
}).catch(() => {

View File

@ -11,7 +11,7 @@ module.exports = {
nodeIntegration: false,
contextIsolation: true,
preload: "src/preload.js",
mainProcessFile: "src/background/main.js",
mainProcessFile: "background/main.js",
lintPreloadFiles: false,
// 添加这段配置确保构建路径正确
outputDir: 'dist_electron',
@ -54,7 +54,7 @@ module.exports = {
// 针对Windows 7的特殊配置
extraResources: [
{
from: "src/background/font",
from: "background/font", // 更新为新路径
to: "font",
filter: ["**/*"],
},