Skip to content

Instantly share code, notes, and snippets.

@dennishall
Created January 29, 2014 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennishall/8695903 to your computer and use it in GitHub Desktop.
Save dennishall/8695903 to your computer and use it in GitHub Desktop.
Prevent grunt imageEmbed from inlining fonts
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