Skip to content

Instantly share code, notes, and snippets.

@mannyyang
Created October 25, 2018 23:59
Show Gist options
  • Select an option

  • Save mannyyang/f5cb6db4e86e2bbd24a659300bf3ca1b to your computer and use it in GitHub Desktop.

Select an option

Save mannyyang/f5cb6db4e86e2bbd24a659300bf3ca1b to your computer and use it in GitHub Desktop.
Generating a SCSS color variable file from a Tailwind config file.
const fs = require('fs');
const path = require('path');
const TailwindConfig = require('./tailwind.config');
const colors = TailwindConfig.colors;
const outPath = path.join(__dirname, 'theme-variables.scss');
// If the file exists, delete it.
fs.unlink(outPath, err => {
if (err && err.code !== 'ENOENT') return console.error(err);
// Iterate through the colors property of the tailwinds config
// and create a scss variable for each color.
Object.keys(colors).forEach(key => {
let line = `$--${key}: ${colors[key]};\n`;
fs.appendFile(outPath, line, err => {
if (err) return console.error(err);
console.log(`wrote ${key} color`);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment