const fs = require("fs"); const archiver = require("archiver"); // 创建一个输出流到指定的 zip 文件 const output = fs.createWriteStream(__dirname + "/../../zip/zy1_in_post_shadowfax.zip"); // 这里可以更改为你想要的文件名11 const archive = archiver("zip", { zlib: { level: 9 }, // 设置压缩级别 }); // 监听关闭事件,打印压缩完成信息 output.on("close", function () { console.log(archive.pointer() + " total bytes"); console.log( "archiver has been finalized and the output file descriptor has closed." ); }); // 捕获警告 archive.on("warning", function (err) { if (err.code === "ENOENT") { // log warning } else { throw err; } }); // 捕获错误 archive.on("error", function (err) { throw err; }); // 将输出流管道到归档文件 archive.pipe(output); // 添加目录到归档文件 archive.directory("dist/", false); // 完成归档 archive.finalize();