Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Tailwind's resolveConfig helper to load the final merged/resolved config #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

philwolstenholme
Copy link

@philwolstenholme philwolstenholme commented Feb 1, 2022

The recommended way of loading Tailwind config programmatically is to use the resolveConfig helper. The reason for this is that in most Tailwind setups, any custom theme config is merged with a set of default config. If we just require the config file directly then we will have access to the custom theme config, but not to any of the default values.

I realised after mentioning this to @hankchizljaw on Twitter that this isn't as useful as I thought it might be for this repo as the prototype creates a set of config items completely from scratch by providing an empty presets array in the Tailwind config, so there are no default values being used, just the values being explicitly set inside the Tailwind config file.

Still, it doesn't hurt to load the config this way and it might be useful for others using this repo as an example, or if, in the future, a client removes the presets config item. As an example, this would let them create custom properties for the borderRadius values provided by Tailwind's default theme, even if they didn't have a customised borderRadius object in their Tailwind config file's theme section.

@netlify
Copy link

netlify bot commented Feb 1, 2022

✔️ Deploy Preview for cube-css-with-tailwind ready!

🔨 Explore the source changes: f3902e8

🔍 Inspect the deploy log: https://app.netlify.com/sites/cube-css-with-tailwind/deploys/61f9a41c1b95420007a398b8

😎 Browse the preview: https://deploy-preview-3--cube-css-with-tailwind.netlify.app

@philwolstenholme
Copy link
Author

For anyone reading this in the future and using the out-of-the-box Tailwind config, if you start generating custom properties for more varied parts of the Tailwind config then you may find that the css-props-generator.js script needs adjusting to handle the different structures used within the default Tailwind config. For example, colors can contain key/pair values like transparent: 'transparent', but also objects with named keys for different shades, and fontSize contains recommended line-height values as well as font-size values. I wrote a bit more about this in an article about using Tailwind config inside Style Dictionary, which might be useful for anyone who stumbles upon this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant