chiiya / laravel-mix-image-minimizer

Image minification for Laravel Mix
MIT License
6 stars 2 forks source link
imagemin images laravel-mix squoosh

Laravel Mix Image Minimizer

Latest Version on NPM npm Software License

This extension adds support for image-minimizer-webpack-plugin to Laravel Mix.

Installation

Install the extension and the implementation of your choice. It's recommended to use squoosh since imagemin is not maintained anymore.

# Using squoosh
npm i -D @chiiya/laravel-mix-image-minimizer @squoosh/lib
# Using imagemin
npm i -D @chiiya/laravel-mix-image-minimizer imagemin imagemin-gifsicle imagemin-mozjpeg imagemin-pngquant imagemin-svgo imagemin-webp

Usage

Require the extension inside your webpack.mix.js and use it like so:

const mix = require('laravel-mix');
require('@chiiya/laravel-mix-image-minimizer');

mix.images({
  webp: true,
});

Options

Name Type Default Description
implementation string squoosh squoosh or imagemin, see image-minimizer-webpack-plugin docs
patterns Array<Object> [{ from: "**/*", to: "images", context: "resources/images" }] pattern option as supported by the copy-webpack-plugin
webp Boolean false If enabled, additional webp versions of all images will be generated
options Object undefined for squoosh, { plugins: ["imagemin-gifsicle", "imagemin-mozjpeg", "imagemin-pngquant", "imagemin-svgo"] } for imagemin Custom configuration for squoosh or imagemin
copyOptions Object { patterns: options.patterns } Additional configuration for the copy-webpack-plugin
webpOptions Object { encodeOptions: { webp: { quality: 90 }}} for squoosh, { plugins: ["imagemin-webp"] } for imagemin Custom squoosh or imagemin configuration for generating webp images