-
-
Save Gomah/2c5e0c26356be898d1a334ea19d8b5d1 to your computer and use it in GitHub Desktop.
Obtain better load time!
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
import tinify from 'tinify'; | |
import walk from 'walk'; | |
import path from 'path'; | |
tinify.key = ''; | |
const dir = path.join(__dirname, '../src/assets'); | |
const files = []; | |
const walker = walk.walk(dir, { followLinks: false }); | |
walker.on('file', (root, stat, next) => { | |
if (stat.name.match(/(.png|.jpg)/gi)) { | |
files.push(`${root}/${stat.name}`); | |
} | |
next(); | |
}); | |
walker.on('end', () => { | |
files.map(file => { | |
tinify.fromFile(file).toFile(file); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment