function minBytes(originalFilePath, destinationFilePath) {
return new Promise(function (resolve, reject){
var Imagemin = require('imagemin');
console.log(originalFilePath) // /app/public/images/temporary/4du_QIGCJb5.jpeg
console.log(destinationFilePath) // /app/public/images/database/9d605a80a2cf926513b7fb/4du_QIGCJb5-0.jpeg
var imagemin = new Imagemin()
.src(originalFilePath)
.dest(destinationFilePath);
imagemin.run(function (error, files) {
if (error != null) {
console.log(error)
reject(error);
} else {
console.log(files);
resolve(destinationFilePath);
}
});
});
};
var minBytesResult = yield Promise.resolve( minBytes(originalFilePath, destinationFilePath) );
当我使用imagemin得到如下错误时,我是否错过了什么?
[TypeError: (input, output, opts) => {
if (!Array.isArray(input)) {
return Promise.reject(new TypeError('Expected an arr...<omitted>...
} is not a constructor]
答案 0 :(得分:1)
这是使用imagemin的v4.0.0方式。
安装:npm install imagemin@4.0.0
,您的代码将正常工作