feat: 构建报错处理

This commit is contained in:
unanmed 2023-10-21 22:01:06 +08:00
parent 9fcae177c5
commit 7a235b2349

View File

@ -60,7 +60,10 @@ const compress = type === 'dist';
await fs.remove('./dist/project/materials/airwall.png'); await fs.remove('./dist/project/materials/airwall.png');
await fs.remove('./dist/project/materials/ground.png'); await fs.remove('./dist/project/materials/ground.png');
await fs.remove('./dist/project/materials/icons_old.png'); await fs.remove('./dist/project/materials/icons_old.png');
} catch {} } catch (e) {
console.log('去除未使用的文件失败!');
console.log(e);
}
// 2. 压缩字体 // 2. 压缩字体
try { try {
@ -122,6 +125,7 @@ const compress = type === 'dist';
]); ]);
} catch (e) { } catch (e) {
console.log('字体压缩失败'); console.log('字体压缩失败');
console.log(e);
} }
// 3. 压缩js插件 // 3. 压缩js插件
@ -153,6 +157,7 @@ const compress = type === 'dist';
await fs.remove('./dist/project/plugin/'); await fs.remove('./dist/project/plugin/');
} catch (e) { } catch (e) {
console.log('压缩插件失败'); console.log('压缩插件失败');
console.log(e);
} }
// 4. 压缩main.js // 4. 压缩main.js
@ -170,14 +175,18 @@ const compress = type === 'dist';
const needCompress = main.slice(endIndex + 17); const needCompress = main.slice(endIndex + 17);
const compressed = babel.transformSync(needCompress)?.code; const compressed = babel.transformSync(needCompress)?.code;
await fs.writeFile('./dist/main.js', nonCompress + compressed, 'utf-8'); await fs.writeFile('./dist/main.js', nonCompress + compressed, 'utf-8');
} catch { } catch (e) {
console.log('main.js压缩失败'); console.log('main.js压缩失败');
console.log(e);
} }
// 5. 杂项 // 5. 杂项
try { try {
await fs.copy('./LICENSE', './dist/LICENSE'); await fs.copy('./LICENSE', './dist/LICENSE');
} catch {} } catch (e) {
console.log('添加杂项失败');
console.log(e);
}
// 6. 资源分离 // 6. 资源分离
if (resorce) { if (resorce) {
@ -186,6 +195,7 @@ const compress = type === 'dist';
// 7. 压缩 // 7. 压缩
if (compress) { if (compress) {
try {
await fs.ensureDir('./out'); await fs.ensureDir('./out');
await compressing.zip.compressDir('./dist', './out/dist.zip'); await compressing.zip.compressDir('./dist', './out/dist.zip');
@ -199,5 +209,9 @@ const compress = type === 'dist';
); );
} }
} }
} catch (e) {
console.log('压缩为zip失败');
console.log(e);
}
} }
})(); })();