Skip to content

Commit 792c979

Browse files
author
Taois
committed
feat: 优化打包
1 parent 79bd20b commit 792c979

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

dashboard/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build:root": "vite build --mode production.root",
1010
"build:apps": "vite build --mode production.apps",
1111
"build:apps-yt": "vite build --mode production.apps-yt",
12+
"build:apps-yt-zip": "vite build --mode production.apps-yt && node scripts/build-zip.js apps-yt",
1213
"build:binary": "node build-binary.js",
1314
"build:binary:win": "node build-binary.js",
1415
"build:binary:optimized": "node build-binary-optimized.js",

dashboard/scripts/build-zip.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { execSync } from 'child_process'
2+
import { resolve, dirname } from 'path'
3+
import { existsSync, renameSync, unlinkSync, rmSync } from 'fs'
4+
import { fileURLToPath } from 'url'
5+
6+
const __dirname = dirname(fileURLToPath(import.meta.url))
7+
const root = resolve(__dirname, '..')
8+
9+
const target = process.argv[2]
10+
if (!target) {
11+
console.error('Usage: node scripts/build-zip.js <target-dir>')
12+
process.exit(1)
13+
}
14+
15+
const srcDir = resolve(root, target, 'drplayer')
16+
const zipFile = resolve(root, target, 'drplayer.zip')
17+
const finalFile = resolve(root, target, 'drplayer')
18+
19+
if (!existsSync(srcDir)) {
20+
console.error(`Source directory not found: ${srcDir}`)
21+
process.exit(1)
22+
}
23+
24+
// Remove leftover zip if exists
25+
if (existsSync(zipFile)) unlinkSync(zipFile)
26+
27+
// Compress contents of srcDir (no nesting — files go directly into zip root)
28+
execSync(
29+
`powershell -Command "Compress-Archive -Path '${srcDir}\\*' -DestinationPath '${zipFile}'"`,
30+
{ stdio: 'inherit' }
31+
)
32+
33+
// Remove the source directory, then rename zip to final name
34+
rmSync(srcDir, { recursive: true, force: true })
35+
renameSync(zipFile, finalFile)
36+
37+
console.log(`Done: ${finalFile}`)

0 commit comments

Comments
 (0)