运行 npm run eject
生成两个文件 运行 npm install
image.pngconfig => paths.js
image.png image.pngconfig => webpack.config.js
image.pngimage.png
// 删除目录
function deleteFolder(path) {
let files = [];
if( fs.existsSync(path) ) {
files = fs.readdirSync(path);
files.forEach(function(file,index){
let curPath = path + "/" + file;
if(fs.statSync(curPath).isDirectory()) { // recurse
deleteFolder(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
try {
fs.rmdirSync(path);
} catch (error) {
}
}
}
// 删除 num run build 编译出来的目录
function deleteOtherDir() {
// 只保留最近的x个版本
const RetainVersionNum = 5;
try {
let webapp_paths = fs.readdirSync(path.join(process.cwd(), 'dist'));
webapp_paths = webapp_paths.filter(item => {
if (item !== 'index.html') {
return parseInt(item);
}
});
webapp_paths = webapp_paths.sort();
if (webapp_paths.length > RetainVersionNum) {
let delete_webapp_paths = webapp_paths.slice(0, webapp_paths.length - RetainVersionNum);
delete_webapp_paths.forEach(delete_webapp_path => {
let delete_webapp_abs_path = path.join(process.cwd(), 'dist', delete_webapp_path);
// console.log('delete_webapp_abs_path -->', delete_webapp_abs_path);
deleteFolder(delete_webapp_abs_path)
})
}
} catch (error) {
}
}
deleteOtherDir();
网友评论