1.1.2 • Published 4 years ago

@zxc1235711/laravel-mix-compress-images v1.1.2

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

@zxc1235711/laravel-mix-compress-images

fixed aravel-mix-compress-images for myself

how to

This modules adds a compressImages function to mix that call the compress_images tool to compress images.

The function take 3 parameters :

  • pattern : the input patterns of the files you want to proceed (string or array)
  • output : the output directory into the mix public path. this param can be a empty string ,it will use your file origin path be you output path.
  • compressParameters: the compress parameters according to https://www.npmjs.com/package/compress-images

Ex.

let mix = require('laravel-mix');
require('@zxc1235711/laravel-mix-compress-images')


/**
 * The following code will create new optimized images files into the ../dist directory.
 *
 * ---------
 * Before :
 * - src/
 *	    - img/
 *	        - test.jpg
 *	        - png/
 *	            - test.webp
 *
 * ---------
 * After :
 * - dist/
 *      - destination/
 *          - test.jpg
 * 	        - png/
 *          	- test.webp
 * - src/
 *	    - img/
 *	        - test.jpg
 *	        - png/
 *	            test.webp
 *
 *
 * As you can see, even png files will be processed because we did not specify
 * a rescrtive input pattern and compressImages has a default processor for png, jpg, svg, and gif.
*/


mix.setPublicPath('../dist');
mix
	.compressImages(
		['img\/**\/*'],
		'destination',
		{
			jpg:{
				engine: 'mozjpeg',
				command:['-quality', '20']
			}
		}
	);