Our general Tailwind setup involves a frontend.config.json and
the usual tailwind.config.js file.
We use values from this JSON file inside the Tailwind config to separate
Tailwind config itself from front end site data. This JSON file is often
read by a project's Webpack set up, a project's JavaScript and a project's
CMS. This set up is, of course, not mandatory to use these plugins, but they
may still prove inspiration for your Tailwind set up all the same.
This documentation site is made using Tailwind and AREA 17 tailwind plugins,
this page documents the config files used for this site.
tailwind.config.js
Breaking that down a little. Firstly require the plugins and then bring in
the front end config file. Then set up Tailwind, JIT if you prefer.
As we have a custom container plugin, we disable the default
Tailwind container class.
Then we bring in the plugins.
Then some we set the various TW theme items to their counterparts in the
config JSON - with some examples like spacing and colours use
plugins as functions to process values from the config JSON.
And finally, a few useful spacing extends.
frontend.config.json
Our config JSON is broken down into:
structure - here we describe the main layout of the site, its
grid and composition, from these :root variables will be made
breakpoints - where each of our breakpoints starts
columns - how many design columns at each breakpoint
container - how wide the main container of the site is
(auto or px/vw/rem)
gutters - gutters definitions
inner - between design columns
outer - on the outside of the main container
ratios - which ratios should be generated for ratio boxes
spacing - define the spacing values for use in Tailwind
spacing classes like h-20 and mx-40
tokens - people rarely think in rems,
they're abstract but as experienced screen developers we've been
talking about pixels for years - we rename the spacing tokens to pixel
values and use a function to convert them to rems and so
mt-16 will give you a margin top of
16px (which in the output CSS will be 1rem)
groups - responsive spacing utility classes, create
global spacing rules that are responsive and systematised, from these
:root variables will be made
color - define site colours
tokens - these are the colour names, such as
red-600, not super human readable, from these
:root variables will be made
borderColor - apply colour tokens (or arbitrary colours)
to human readable systematised named classes, eg:
border-primary for your primary border, might map to
primary: grey-5, from these :root variables
will be made
textColor - same for text classes
backgroundColor - and background colours
typography - define the site type styles
families - firstly the families being used, from these
:root variables will be made
typesets - responsive type sets, where breakpoint
overrides can be specified and typography can be systematised