Here are the steps that I took to create this file:
<olclass="spaced-y-6">
<li>
<pmarkdown="1">**Get the default configuration**. This is done using `require('tailwindcss/defaultConfig')()`. Essentially this has the same contents as the current `tailwind.js` file, though now it’s owned and maintained within Tailwind itself, and not by the user.</p>
<p>Also any new or updated values within the default configuration will be automatically available.</p>
<pmarkdown="1">This line is present but commented out in the current generated `tailwind.js` file.</p>
</li>
<li>
<pmarkdown="1">**Create the colors object.** This will by default override Tailwind’s default colours, however you can add `...defaultConfig.colors` to include them and then add or edit values as needed.</p>
<pmarkdown="1">In this example, I’m overridding the value used for the `black` colour classes to match the existing colour in the other CSS.</p>
</li>
<li>
<pmarkdown="1">**Return the main configuration object.** For sites with no overrides, this could just be `module.exports = defaultConfig` for a minimal configuration.</p>
<pmarkdown="1">To extend the defaults, add `...defaultConfig` at the beginning.</p>
</li>
<li>
<pmarkdown="1">**Assign our colours.** Use them for `colors`, `textColors`, `backgroundColors` and `borderColours`.</p>
</li>
<li>
<pmarkdown="1">**Add any plugins**. I use plugins on most projects, in this case I’m using [tailwindcss-interaction-variants](https://www.npmjs.com/package/tailwindcss-interaction-variants) and [tailwindcss-spaced-items](https://www.npmjs.com/package/tailwindcss-spaced-items). Usually the default `container` plugin would be here too.</p>
</li>
<li>
<pmarkdown="1">**Add or override modules.** Here I’m adding the `hocus` (hover and focus) variant provided by the interaction variants plugin to the text style classes.</p>
</li>
<li>
<pmarkdown="1">**Add or override options.** As this markup was originally from a Drupal website, I needed to override some of the options values. I’ve added the `tw-` prefix to avoid Tailwind classes from clashing with Drupal’s default markup, and set all Tailwind classes to use `!important` so that they override any existing styles.</p>
</li>
</ol>
This file is only 27 lines long, so considerably shorter than the default file,
and I think that it’s much easier to see what your additional and overridden
values are, as well able to quickly recognise whether a class is generated from
a custom value or from a Tailwind default value.
To move this file to the new format I think would be much easier as there’s no
default configuration to filter out, and you can move across only what is
needed.
## Other changes
### Consistent spacing for padding and margin
Similar to defining colours, you could also set some standard spacing values,
and using those for padding, margin and negative margin to ensure that they are
all consistent.
In this case, we can use `defaultConfig.margin` to get the default, add or
override any values, and then assign it to the relevant sections of the main
object.
```js
const spacing = {
...defaultConfig.margin,
'2px': '2px',
};
module.exports = {
...defaultConfig,
// ...
padding: spacing,
margin: spacing,
negativeMargin: spacing,
// ...
};
```
### Picking values with lodash
In the opposite to extending, if we wanted to limit the number of values within
a part of the configuration, we can do that too. I’d suggest using the
[pick method](https://lodash.com/docs/4.17.11#pick) provided by
[Lodash](https://lodash.com).
From the documentation:
> Creates an object composed of the picked object properties.
For example, if we only wanted normal, medium and bold font weights: