Skip to content

Instantly share code, notes, and snippets.

@willread
Last active August 29, 2015 14:17
Show Gist options
  • Save willread/8fa10bac81160f1f45b8 to your computer and use it in GitHub Desktop.
Save willread/8fa10bac81160f1f45b8 to your computer and use it in GitHub Desktop.
Convert rem units to pixels
var glob = require('glob');
var _ = require('lodash');
var fs = require('fs');
var rem = 18;
var path = '/path/stuff/**/*.css';
glob(path, {}, function(err, files) {
_.each(files, function(file) {
fs.readFile(file, 'utf-8', function(err, data) {
var converted = data.replace(/(\d+.?\d*)rem/g, function(match, p1) {
return Math.floor(p1 * rem) + 'px';
});
fs.writeFile(file, converted, function(err) {
console.log('converted ' + file);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment