Skip to content

Instantly share code, notes, and snippets.

@JLarky
Created August 11, 2020 00:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JLarky/2d2591294e6c0215e0d3385fcd72af67 to your computer and use it in GitHub Desktop.
Save JLarky/2d2591294e6c0215e0d3385fcd72af67 to your computer and use it in GitHub Desktop.
Expose tailwind color palette to be able to access tailwind config from javascript/browser
import { theme } from './tailwind.static';
console.log(theme.extend.colors.gray[500]);
const prettier = require('prettier');
const fs = require('fs');
const tailwind = require('./tailwind.config.js');
// you can skip prettier if you don't need it
prettier.resolveConfigFile().then((configFile) => {
prettier.resolveConfig(configFile).then((options) => {
options = { parser: 'babel', ...options };
const fmt = (str) => prettier.format(str, options);
const write = (fileName, fileContent) => {
fs.writeFileSync(fileName, fmt(fileContent), 'utf8');
console.log(`Wrote ${fileName}`);
};
run(write);
});
});
const run = (write) => {
// edit this to get access to different parts of config
const {
theme: {
extend: { fontFamily, colors },
},
} = tailwind;
const tailwindStatic = {
theme: {
extend: { fontFamily, colors },
},
};
write(
'./src/tailwind.static.js',
`// DO NOT EDIT: generated by \`yarn generate\`
module.exports = ${JSON.stringify(tailwindStatic)};`
);
};
{
"scripts": {
"generate": "node generate.js",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment