Laravel Mix imgmin
Laravel Mix extension to compress images [png,jpg,jpeg,svg,gif,bmp,ico] with TinyPNG.
Note
This extension uses Gulp 4. This can create unexpected behavior if you are using older version of Gulp inside your project.
Installation
Install the extension:
npm install laravel-mix-imgmin
Or if you prefer yarn:
yarn add laravel-mix-imgmin
Next require the extension inside your Laravel Mix config and call imgmin()
in your pipeline:
// webpack.mix.js
const mix = require('laravel-mix');
require('laravel-mix-imgmin');
mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.imgmin();
Options
Default options
If nothing is passed to the extension inside your Laravel Mix config, the following options will be used:
{
input: 'resources/img',
publicPath: 'public',
output: 'img',
tinyPngKey: null,
debug: false
}
Option details
-
input
(string). Your input directory where images are located. -
publicPath
(string). Your application's public path. -
output
(string). Your output directory where compressed images will be saved. -
tinyPngKey
(string or null). Your TinyPNG key. If you don't provide TinyPNG key, then default gulp-imagemin package will be used. TinyPNG is recommended for the best results. -
debug
(boolean). Whenever to log extension events messages to the console.
New in version 0.2.x
- Now supports
laravel-mix
version 6