Created
January 29, 2014 20:07
-
-
Save dennishall/8695903 to your computer and use it in GitHub Desktop.
Prevent grunt imageEmbed from inlining fonts
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
var fs = require('fs'); | |
var fontFilenames = ['c.eot', 'ci.eot', 'c.svg', 'ci.svg', 'c.ttf', 'ci.ttf', 'c.woff', 'ci.woff']; | |
grunt.registerTask('fontPrep', 'Move Celeste fonts so that they are not handled by imageEmbed.', function(){ | |
// create a temp folder | |
fs.mkdirSync('css/fonts/tmp'); | |
fontFilenames.forEach(function(name){ | |
// move the Celeste fonts t othe temp folder | |
fs.renameSync('css/fonts/'+name, 'css/fonts/tmp/'+name); | |
// create dummy files that are large enough (>32k) to cause imageEmbed to skip them | |
fs.writeFileSync('css/fonts/'+name, (new Array(35000)).join(' ')); | |
}); | |
console.log('Moved Celeste fonts so that they are not handled by imageEmbed.'); | |
}); | |
grunt.registerTask('fontCleanup', 'Counterpart to fontPrep.', function(){ | |
// create a temp folder | |
fontFilenames.forEach(function(name){ | |
// move the Celeste fonts t othe temp folder | |
fs.renameSync('css/fonts/tmp/'+name, 'css/fonts/'+name); | |
}); | |
fs.rmdirSync('css/fonts/tmp'); | |
console.log('Moved Celeste back.'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment