kevinabouhanna/abouhassan

Find a way to convert images to webp and compress automatically

kevinabouhanna opened this issue · 0 comments

npm install @netlify/plugin-image-optim

build.js
----------------
const imagemin = require('imagemin');
const imageminWebp = require('imagemin-webp');

(async () => {
  await imagemin(['src/images/*.{jpg,png}'], {
    destination: 'dist/images',
    plugins: [
      imageminWebp({quality: 85})
    ]
  });

  console.log('Images optimized');
})();
package.json
---------------
{
  "scripts": {
    "build": "node build.js"
  }
}

and/or
npm install imagemin imagemin-webp

netlify toml
[build]
command = "npm run build"

[[plugins]]
package = "@netlify/plugin-image-optim"