Skip to content

Instantly share code, notes, and snippets.

@Gomah
Forked from nqthqn/smaller.js
Last active May 23, 2017 04:33
Show Gist options
  • Save Gomah/2c5e0c26356be898d1a334ea19d8b5d1 to your computer and use it in GitHub Desktop.
Save Gomah/2c5e0c26356be898d1a334ea19d8b5d1 to your computer and use it in GitHub Desktop.
Obtain better load time!
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