Skip to content

Instantly share code, notes, and snippets.

@khavari
Created January 6, 2019 11:20
Show Gist options
  • Save khavari/38d7cd4fa7c247c30f8f64023c4949ac to your computer and use it in GitHub Desktop.
Save khavari/38d7cd4fa7c247c30f8f64023c4949ac to your computer and use it in GitHub Desktop.
laravel-mix image minifier
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