I'm trying to convert more than one PNG and JPG file to WebP using imagemin-webp instead of using cwebp to convert one at a time, but it is not working for some reason.
Everything I've done so far:
1- I installed Node JS v10.16.0;
2- From inside my project i created the package.json file using the command:
npm init -y
;
3- Still within the directory of my project i ran the command npm install imagemin imagemin-webp
;
4- Then i created a webp.js to hold the code that should convert the images and then i executed it with the node webp.js
command.
Following is the code inside webp.js:
const imageminWebp = require('imagemin-webp');
imagemin(['_imgs/*.{jpg,png}'], '_imgs', {
use: [
imageminWebp({quality: 50})
]
}).then(() => {
console.log('Images optimized');
});
I thought that once it was executed, all the files inside the _imgs folder would be converted to webp, but when I look inside the folder there are only the PNG and JPG files there.
When I run that code I get the message "Optimized image" but despite this, the WebP images are not generated.
Is there anything else i need to do to make it work?