Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. const fs = require('fs');
  2. const postcss = require('postcss');
  3. const postcssJs = require('postcss-js');
  4. // e.g. body { font-size: 14px } h1 { font-size: 21px; }
  5. const cssFile = fs.readFileSync('./path/to/file.css');
  6.  
  7. const css = postcss.parse(cssFile.toString());
  8. const cssJsObject = postcssJs.objectify(css);
  9.  
  10. // e.g. module.exports = { body: { fontSize: "14px" }, h1: { fontSize: "21px" };
  11. fs.writeFileSync('./path/to/file.js', `module.exports = ${JSON.stringify(cssJsObject)};`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement