J
J
Junior Development2021-05-22 16:18:11
Laravel
Junior Development, 2021-05-22 16:18:11

How to optimize images in laravel mix?

I decided to try an alternative to gulp and work with Laravel Mix.
In office The documentation for Laravel Mix explains everything quite clearly, however, I had difficulties with optimizing images.

My assembly code:

let mix = require('laravel-mix');

const ImageminPlugin = require('imagemin-webpack-plugin').default;
const CopyWebpackPlugin = require('copy-webpack-plugin');
const imageminMozjpeg = require('imagemin-mozjpeg');

mix.webpackConfig({
    plugins: [
        new CopyWebpackPlugin([{
            from: 'src/img',
            to: 'build/img', 
        }]),
        new ImageminPlugin({
            test: /\.(jpe?g|png|gif|svg)$/i,
            plugins: [
                imageminMozjpeg({
                    quality: 80,
                })
            ]
        })
    ]
});


Gives an error message
ValidationError: Invalid options object. Copy Plugin has been initialized using an opti
ons object that does not match the API schema.


What do you use when optimizing images in Laravel Mix?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey delphinpro, 2021-05-22
@delphinpro

It's written the same: wrong CopyWebpackPlugin plugin settings object.
Check out the documentation https://webpack.js.org/plugins/copy-webpack-plugin/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question