🔧 构建完成后自动打包 dist.zip

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-27 18:34:11 +08:00
parent 450505715a
commit 9a3652d767
3 changed files with 29 additions and 2 deletions
+1
View File
@@ -2,6 +2,7 @@
node_modules
pnpm-lock.yaml
/dist
/dist.zip
/tests/e2e/videos/
/tests/e2e/screenshots/
+3 -2
View File
@@ -4,8 +4,9 @@
"scripts": {
"dev": "vite --host",
"prod": "vite --mode production",
"build": "vite build",
"build:prod": "vite build --mode production",
"build": "vite build && node scripts/zip-dist.mjs",
"build:prod": "vite build --mode production && node scripts/zip-dist.mjs",
"zip:dist": "node scripts/zip-dist.mjs",
"serve": "vite preview --host",
"typecheck": "vue-tsc --noEmit"
},
+25
View File
@@ -0,0 +1,25 @@
import { execFileSync } from 'node:child_process';
import { existsSync, rmSync, statSync } from 'node:fs';
import { resolve } from 'node:path';
const root = process.cwd();
const distDir = resolve(root, 'dist');
const zipPath = resolve(root, 'dist.zip');
if (!existsSync(distDir) || !statSync(distDir).isDirectory()) {
console.error('[zip-dist] dist 目录不存在,请先完成构建');
process.exit(1);
}
if (existsSync(zipPath)) {
rmSync(zipPath);
}
// 压缩 dist 内文件到根级(解压即 index.html / assets,便于直接上传部署)
execFileSync('zip', ['-qr', zipPath, '.', '-x', '*.DS_Store', '-x', '__MACOSX/*'], {
cwd: distDir,
stdio: 'inherit',
});
const sizeMb = (statSync(zipPath).size / (1024 * 1024)).toFixed(2);
console.log(`[zip-dist] 已生成 ${zipPath}(${sizeMb} MB)`);