-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42d5eb8
commit dff8b18
Showing
7 changed files
with
1,556 additions
and
48 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module.exports = async function(site) { | ||
const imagemin = require('imagemin'); | ||
const imageminMozjpeg = require('imagemin-mozjpeg'); | ||
const imageminPngquant = require('imagemin-pngquant'); | ||
const glob = require('glob'); | ||
const path = require('path'); | ||
|
||
const { BUILD, STATIC, IMAGES } = require('../utils/constants'); | ||
|
||
try { | ||
let message = 'Optimising images'; | ||
site.logger.await(message); | ||
|
||
// this monstrosity is because imagemin does not support | ||
// overwriting the images when a glob is provided. | ||
// PRs and issues related to this are closed without any | ||
// clear path forward | ||
let images = glob.sync(`${STATIC}/**/*.+(${IMAGES.join('|')})`); | ||
|
||
// skipping favicons | ||
images = images.filter(image => !image.includes('favicon')); | ||
|
||
let imageOptimPromises = []; | ||
for (let index = 0; index < images.length; index++) { | ||
let image = images[index]; | ||
imageOptimPromises.push( | ||
imagemin([image], path.dirname(image.replace(STATIC, `${BUILD}/${STATIC}`)), { | ||
plugins: [ | ||
imageminMozjpeg(), | ||
imageminPngquant({quality: '65-80'}) | ||
] | ||
}) | ||
); | ||
} | ||
|
||
await Promise.all(imageOptimPromises); | ||
site.logger.success(message); | ||
} catch (error) { | ||
throw error; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.