From 9a3652d767ae82024fc06674f586d9775df66c80 Mon Sep 17 00:00:00 2001 From: b2894lxlx <517289602@qq.com> Date: Tue, 27 Oct 2026 18:34:11 +0800 Subject: [PATCH] =?UTF-8?q?:wrench:=20=E6=9E=84=E5=BB=BA=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E6=89=93=E5=8C=85=20dist.zip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .gitignore | 1 + package.json | 5 +++-- scripts/zip-dist.mjs | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 scripts/zip-dist.mjs diff --git a/.gitignore b/.gitignore index eb97814..3fa5cf4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ node_modules pnpm-lock.yaml /dist +/dist.zip /tests/e2e/videos/ /tests/e2e/screenshots/ diff --git a/package.json b/package.json index ee42d0f..41bbadd 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/scripts/zip-dist.mjs b/scripts/zip-dist.mjs new file mode 100644 index 0000000..44da047 --- /dev/null +++ b/scripts/zip-dist.mjs @@ -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)`);