Created
August 11, 2020 00:55
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { theme } from './tailwind.static'; | |
console.log(theme.extend.colors.gray[500]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)};` | |
); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"generate": "node generate.js", | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment