Skip to content

Instantly share code, notes, and snippets.

@naffiq
Last active October 10, 2021 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naffiq/e5e8e1d362dc3ebc6976548caab2c0ae to your computer and use it in GitHub Desktop.
Save naffiq/e5e8e1d362dc3ebc6976548caab2c0ae to your computer and use it in GitHub Desktop.
Image min for Laravel Mix

Based on this comment.

npm install --save-dev imagemin-webpack-plugin copy-webpack-plugin imagemin-mozjpeg
const { 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: 'resources/assets/images',
            to: 'img', // Laravel mix will place this in 'public/img'
        }]),
        new ImageminPlugin({
            test: /\.(jpe?g|png|gif|svg)$/i,
            plugins: [
                imageminMozjpeg({
                    quality: 80,
                })
            ]
        })
    ]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment