Skip to content

Instantly share code, notes, and snippets.

@Walkeryr
Created February 25, 2020 08:55
Show Gist options
  • Save Walkeryr/4d6f2eea6450e9caa7aba875213d0f30 to your computer and use it in GitHub Desktop.
Save Walkeryr/4d6f2eea6450e9caa7aba875213d0f30 to your computer and use it in GitHub Desktop.
Script to convert all rems to pixels
var fs = require('fs');
let doc = fs.readFileSync('dist/css/app.b528a7e0.css', 'utf8');
console.log(doc.replace(/(:|\s?){1}([0-9-]*\.?[0-9]*)(rem)/g, function (match, delimeterGroup, numberGroup, sizeGroup, offset, string) {
let pixelSize = Number(numberGroup) * 16
if (delimeterGroup === ':') {
return `:${pixelSize}px`
} else if (delimeterGroup === ' ') {
return ` ${pixelSize}px`
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment