chore: 提高压缩级别

This commit is contained in:
unanmed 2025-10-22 14:44:16 +08:00
parent f496175bb2
commit f9b6d8271e
2 changed files with 25 additions and 7 deletions

View File

@ -572,13 +572,21 @@ async function buildGame() {
) )
); );
const scripts = archiver('zip'); const scripts = archiver('zip', {
scripts.directory('packages/', resolve(process.cwd(), 'packages')); store: false,
zlib: {
level: 9
}
});
scripts.directory(resolve(process.cwd(), 'packages'), 'packages/');
scripts.directory( scripts.directory(
'packages-user/', resolve(process.cwd(), 'packages-user'),
resolve(process.cwd(), 'packages-user') 'packages-user/'
); );
scripts.directory('src/', resolve(process.cwd(), 'src')); scripts.directory(resolve(process.cwd(), 'src'), '/src');
scripts.file(resolve(process.cwd(), 'public', 'main.js'), {
name: 'main.js'
});
const output = createWriteStream(resolve(distDir, 'source-code.zip')); const output = createWriteStream(resolve(distDir, 'source-code.zip'));
scripts.pipe(output); scripts.pipe(output);
@ -626,7 +634,11 @@ async function buildGame() {
try { try {
await zip.compressDir( await zip.compressDir(
resolve(distDir), resolve(distDir),
resolve(process.cwd(), 'dist.zip') resolve(process.cwd(), 'dist.zip'),
{
compress: true,
compressionLevel: 9
}
); );
await emptyDir(tempDir); await emptyDir(tempDir);

View File

@ -67,7 +67,13 @@ async function compressFiles(files: ResourceContent[]) {
const dir = `${v.type}/${v.name}`; const dir = `${v.type}/${v.name}`;
zip.file(dir, v.content); zip.file(dir, v.content);
}); });
const buffer = await zip.generateAsync({ type: 'uint8array' }); const buffer = await zip.generateAsync({
type: 'uint8array',
compression: 'DEFLATE',
compressionOptions: {
level: 9
}
});
const hash = fileHash(buffer); const hash = fileHash(buffer);
const name = `resource.${hash}.h5data`; const name = `resource.${hash}.h5data`;