简体   繁体   中英

Nodejs imagemin how do I pass in the list of files to process

Trying to get imagemin to work in Nodejs. This is my code:

var imagemin = require('imagemin');
var imageminPngquant = require('imagemin-pngquant');
var PNGImages = ['images/image1.png', 'images/image2.png'];

imagemin(PNGImages, 'build', {
    plugins: [
        imageminPngquant({
            quality: '65-80'
        })
    ]
});

But I keep getting the error:

(node:22744) UnhandledPromiseRejectionWarning: ArgumentError: Expected argument to be of type `array` but received type `string`

What am I doing wrong? Thanks.

Found the answer.
imageminPngquant was throwing the error due to the 65-80 in the quality setting and not because of the PNGImages array.

:)

Pass Quality as below

imageminPngquant({
            quality: [65, 80]
        })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM