chiiya / laravel-mix-image-minimizer

Image minification for Laravel Mix
MIT License
6 stars 2 forks source link

How to use - Question about images optimisation #1

Closed JeromeDeBoysere closed 2 years ago

JeromeDeBoysere commented 2 years ago

Hello there,

I have just discovered your repo, but I can make it work at 100% on my project. I think I miss something but I dont know what.

In my webpack.mix.js, I have:

// Laravel Mix
const mix = require('laravel-mix');

// https://www.npmjs.com/package/@chiiya/laravel-mix-image-minimizer
require('@chiiya/laravel-mix-image-minimizer');

// Options for Laravel Mix
// https://laravel-mix.com/docs/4.0/options
mix.options({
  postCss: [require('autoprefixer')],
  cssNano: {
    discardComments: {removeAll: true},
  }
}).setPublicPath('public');

mix.setResourceRoot('../..'); 

mix.images({
  implementation: 'squoosh',
  patterns: [{ from: "resources/assets/images", to: "assets/images" }],
  webp: true,
  webpOptions: { encodeOptions: { webp: { quality: 90 }}}
});

// ...

The images are copied from /resources/assets/images to /public/assets/images so no problem with this. But, they have the same weight so I guess the images in /public/assets/images are not optimised/compressed after a npm run dev.

Any idea why?

Thank you for your help

chiiya commented 2 years ago

Have you tried running npm run prod? Images are only optimized in production mode.

JeromeDeBoysere commented 2 years ago

Have you tried running npm run prod? Images are only optimized in production mode.

Awww yes! It does work!

I thought I had to use if (mix.inProduction()) { ... } for that.

Thanks!!