refactor: 优化清理代码

This commit is contained in:
winixt 2023-01-06 17:23:06 +08:00
parent 3c5113ce74
commit b926ae87ec

View File

@ -8,19 +8,17 @@ const path = require('path');
async function handleCacheClean(cwd) {
return new Promise((resolve, reject) => {
const cachePath = path.join(cwd, '.cache');
const cachePath = path.join(cwd, '.cache/webpack');
require('get-folder-size')(cachePath, (err, size) => {
if (err) {
reject(err);
} else {
// 大于 5G 清除缓存,修复 webpack 缓存无限增长问题
// https://github.com/webpack/webpack/issues/13291
size = (size / 1024 / 1024 / 1024).toFixed(2);
if (size > 5) {
require('fs-extra').removeSync(cachePath);
}
resolve(size);
return reject(err);
}
// 大于 5G 清除缓存,修复 webpack 缓存无限增长问题
// https://github.com/webpack/webpack/issues/13291
if (size > 5 * 1024 * 1024 * 1024) {
require('fs-extra').removeSync(cachePath);
}
resolve(size);
});
});
}