Cannot overwrite theme fontFamily when using presets to override
See original GitHub issueDescribe the problem:
I have moved some config into separate preset files. One of these preset files is called tailwind.brand.js
and I am including this along with several others in my main tailwind.config.js
file like so:
module.exports = {
presets: [
require('./src/tailwind/tailwind.brand.js'),
// require('./src/tailwind/tailwind.project.js'),
require('./src/tailwind/tailwind.colors.js'),
require('./src/tailwind/tailwind.spacing.js'),
require('./src/tailwind/tailwind.opacity.js'),
require('./src/tailwind/tailwind.zindex.js'),
require('./src/tailwind/tailwind.grid.js')
],
purge: {
mode: 'all',
content: [
'./templates/**/*.html',
'./templates/**/*.php',
'./src/**/*.js'
],
options: {
whitelistPatterns: [/lazyload/, /grayscale-up/, /blur-up/],
}
},
theme: {
container: {
center: true,
padding: '1.5rem',
},
},
variants: {
extend: {
// display: ['group-hover']
// translate: ['group-hover']
}
},
corePlugins: {},
plugins: []
};
Within the tailwind.brand.js
I am over-riding the font families and adding/extending some colours like so:
module.exports = {
theme: {
fontFamily: {
'sans': ['Poppins', 'sans-serif'],
'serif': [''],
'brand': [],
},
extend: {
colors: {
// Extends one of new TailwindCSS colour schemes
// lightblue: colors.lightBlue,
'brand': {
'orange': '#fe5b00',
'red': '#ff0000'
}
},
}
}
};
However, on the buildCSS the fontFamily is not getting replaced and it is using the default family settings.
If I move the fontFamily code out of the tailwind.brand.js
and directly into the tailwind.config.js
then it works ok.
fontFamily: {
'sans': ['Poppins', 'sans-serif'],
'serif': [''],
'brand': [],
},
So it appears that the the defaults are not overridden when inside a preset.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Theme Configuration - Tailwind CSS
Overriding the default theme. This will completely replace Tailwind's default configuration for that key, so in the example above none of the default...
Read more >theme.json and font families in WP 5.9 | WordPress.org
I'm developing a block theme for WP 5.9 and added a font families section to its theme.json file: { "version": 2, "settings": {...
Read more >How to Change Font in WordPress Theme (Any Theme)
In this post, we'll start by showing you how to change font in a WordPress theme using its built-in options. Then, if your...
Read more >Theme.json typography options: Font family and size
Learn about the theme.json typography options for font family and font size and how to add custom google fonts with the webfonts API....
Read more >How to Change Fonts in Your WordPress Theme (5 Easy ...
In this article, we'll show you how to change font in WordPress using 5 different ways, so you can easily change fonts using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey @terryupton thanks for that. After taking a closer look at this it seems that the presets are working as expected, although the behaviour may be a little unintuitive.
Basically each of your presets in turn extends from the default config. From the docs:
You can think of it like this:
So the font you’re specifying in
customStuff1
is overridden by the default config thatpreset2
extends. The solution is to setpresets
to an empty array in each of your presets:Then, to ensure that you still get the Tailwind defaults you can either leave the
presets
key off your first preset, or add it manually to your main config file:Hopefully that makes sense, and I have opened a pull request on your repo with the changes I described 👍
Hey @bradlc - I have now setup a new branch
tailwind-presets-issue
that illustrates the issue. I have rerun the build (using none production) and you can see that the ‘Poppins’ font stack is no longer used when it is called within/src/tailwind/tailwind.brand.js
Shout me if you need anything clarifying.