Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stephan-v's avatar

Laravel mix image workflow.

With Gulp the workflow for images was kind of straight forward. I could easily maintain my gulp file myself and run an image minifier from gulp to minify my resource images to actual production images.

Laravel mix helps to make things a lot easier when it comes to dealing with webpack but I am still unsure on how to minify images and work with them in combination with laravel mix.

Does anybody have an example workflow set up on how to minify images from one folder as input to a folder of minified images using the webpack config from laravel mix?

Am I still suppose to use gulp alongside of webpack here?

0 likes
7 replies
Lunah's avatar

Also interested in this. I've used image min packages but they all rely on gulp.

2 likes
impbob36's avatar

Was holding off upgrading until I figured something out

impbob36's avatar

OK ... got it.

I use Imagemin plugin for Webpack - https://github.com/Klathmon/imagemin-webpack-plugin

Install Imagemin plugin for Webpack

npm install imagemin-webpack-plugin

Update webpack.mix.js

// Add near top of file
let ImageminPlugin = require( 'imagemin-webpack-plugin' ).default;


mix.webpackConfig( {
    plugins: [
        new ImageminPlugin( {
//            disable: process.env.NODE_ENV !== 'production', // Disable during development
            pngquant: {
                quality: '95-100',
            },
            test: /\.(jpe?g|png|gif|svg)$/i,
        } ),
    ],
} )

and copy over the image files

mix.copy( 'resources/assets/images', 'public/images', false );
1 like
devTriple's avatar

I tried this, but I get TypeError: ImageminPlugin is not a constructor

impbob36's avatar

I just tried it on a fresh copy and its working for me. Double check the following line:

let ImageminPlugin = require( 'imagemin-webpack-plugin' ).default;

It needs the .default on the end otherwise you'll get

TypeError: ImageminPlugin is not a constructor

I think Jeffery is working on adding some image minification into the official package sometime soon.

1 like

Please or to participate in this conversation.