Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const postcss = require('postcss');
- const postcssJs = require('postcss-js');
- // e.g. body { font-size: 14px } h1 { font-size: 21px; }
- const cssFile = fs.readFileSync('./path/to/file.css');
- const css = postcss.parse(cssFile.toString());
- const cssJsObject = postcssJs.objectify(css);
- // e.g. module.exports = { body: { fontSize: "14px" }, h1: { fontSize: "21px" };
- fs.writeFileSync('./path/to/file.js', `module.exports = ${JSON.stringify(cssJsObject)};`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement