使用JSZip-sync这个包代替jszip即可。
npm地址:https://www.npmjs.com/package/jszip-sync
用法
var JSZip = require("jszip-sync");
var zip = new JSZip();
//相较于jszip 此方法只是在外层包裹了zip.sync,其他用法都和jszip用法一致
var zipped = zip.sync(function() {
// put some stuff in there
zip.file("Hello.txt", "Hello World\n");
var img = zip.folder("images");
img.file("smile.gif", imgData, {base64: true});
// call regular async methods
var data = null;
zip.generateAsync({type: "arraybuffer", compression: "DEFLATE"})
.then(function(content) {
data = content;
});
return data;
});