Created
October 21, 2018 11:15
-
-
Save schalkneethling/c5b710446bd316247b1d213b81ea62b6 to your computer and use it in GitHub Desktop.
Example of batch compressing images using ImageMin with Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const imagemin = require('imagemin'); | |
const imageminJpegTran = require('imagemin-jpegtran'); | |
const imageminPngQuant = require('imagemin-pngquant'); | |
async function optim() { | |
const files = await imagemin( | |
['./live-examples/media/**/*.{jpg,png}'], | |
'./build/images', | |
{ | |
plugins: [ | |
imageminJpegTran(), | |
imageminPngQuant({ quality: '65-80' }) | |
] | |
} | |
); | |
for (let file in files) { | |
console.log(files[file]); | |
} | |
console.log(`Image compression completed ${files}`); | |
} | |
optim(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment