I'm migrating from Tailwind CSS v3 to v4, and I've hit a roadblock with custom colors. In v3, I was able to import a JSON file with color values directly into my tailwind.config.js:
const colors = require('./colors.json');
module.exports = {
theme: {
extend: {
colors: {
primary: colors.primary,
secondary: colors.secondary,
tertiary: colors.tertiary,
}
}
}
// ...other config
}
In Tailwind CSS v4, the configuration has changed to use CSS variables in the @theme section of a CSS file.
In my project, these colors are fetched from an API endpoint, which is why I need to keep them in a JSON format that can be updated dynamically. I need a way to import my colors.json into the CSS file that contains my @theme declarations.
So my question is, how can I import dynamic color values from a JSON file into Tailwind CSS v4's @theme section?
@plugin ...in your Tailwind CSS config.