From 7a235b23491ba24cb86c458e6b49b11383673405 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 21 Oct 2023 22:01:06 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9E=84=E5=BB=BA=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/build.ts | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/script/build.ts b/script/build.ts index df222b1..996f844 100644 --- a/script/build.ts +++ b/script/build.ts @@ -60,7 +60,10 @@ const compress = type === 'dist'; await fs.remove('./dist/project/materials/airwall.png'); await fs.remove('./dist/project/materials/ground.png'); await fs.remove('./dist/project/materials/icons_old.png'); - } catch {} + } catch (e) { + console.log('去除未使用的文件失败!'); + console.log(e); + } // 2. 压缩字体 try { @@ -122,6 +125,7 @@ const compress = type === 'dist'; ]); } catch (e) { console.log('字体压缩失败'); + console.log(e); } // 3. 压缩js插件 @@ -153,6 +157,7 @@ const compress = type === 'dist'; await fs.remove('./dist/project/plugin/'); } catch (e) { console.log('压缩插件失败'); + console.log(e); } // 4. 压缩main.js @@ -170,14 +175,18 @@ const compress = type === 'dist'; const needCompress = main.slice(endIndex + 17); const compressed = babel.transformSync(needCompress)?.code; await fs.writeFile('./dist/main.js', nonCompress + compressed, 'utf-8'); - } catch { + } catch (e) { console.log('main.js压缩失败'); + console.log(e); } // 5. 杂项 try { await fs.copy('./LICENSE', './dist/LICENSE'); - } catch {} + } catch (e) { + console.log('添加杂项失败'); + console.log(e); + } // 6. 资源分离 if (resorce) { @@ -186,18 +195,23 @@ const compress = type === 'dist'; // 7. 压缩 if (compress) { - await fs.ensureDir('./out'); - await compressing.zip.compressDir('./dist', './out/dist.zip'); + try { + await fs.ensureDir('./out'); + await compressing.zip.compressDir('./dist', './out/dist.zip'); - // 压缩资源 - if (resorce) { - const resources = await fs.readdir('./dist-resource'); - for await (const index of resources) { - await compressing.zip.compressDir( - `./dist-resource/${index}`, - `./out/${index}.zip` - ); + // 压缩资源 + if (resorce) { + const resources = await fs.readdir('./dist-resource'); + for await (const index of resources) { + await compressing.zip.compressDir( + `./dist-resource/${index}`, + `./out/${index}.zip` + ); + } } + } catch (e) { + console.log('压缩为zip失败!'); + console.log(e); } } })();