Open BryceRussell opened 6 months ago
Tailwind 4 and also UnoCSS (according to Adam) are great because they don't require any user input.
The... not easiest.. But fairly sleek way to add support for TW3 is to export a wrapTailwindConfig
function from your theme. At least this is what I do with my theme at the moment but granted, it's not the nicest thing.
import {
createResolver
} from 'astro-integration-kit'
import plugin from 'tailwindcss/plugin'
import { type Config, } from 'tailwindcss'
const { resolve } = createResolver(__dirname)
export const GalaxyTailwindContent = [
resolve('../**/*.{astro,html,js,ts,jsx,tsx,css}'),
]
export const GalaxyTailwindPlugin = () => plugin(() => {}, {
theme: {
fontFamily: {
'galaxy-display': 'Titillium Web',
'galaxy-body': 'Albert Sans',
},
},
});
export const wrapTailwindConfig = (config: Config): Config => {
if (!config.content) {
config.content = []
}
if (!config.plugins) {
config.plugins = []
}
(config.content as unknown[]).push(
...GalaxyTailwindContent,
)
config.plugins.push(GalaxyTailwindPlugin())
return config
}
Then the user
// tailwind.config.js
import { wrapTailwindConfig } from 'my-theme/tailwind'
export default wrapTailwindConfig([...}) // they can then pass their own config here.
It would be better if you could just export a tailwind plugin. But neither TW3 plugins or extends let you add content
paths. I don't know, not a perfect solution but thought I'd spitball
These are some great insights, thanks for the info!
I didn't realize that plugins could not extend content
, that makes this a lot harder! This also has to support, multiple themes in a single project, I wonder if doing something like this would work:
import { mergeTailwindConfigs } from 'astro-theme-provider';
import configOne from 'my-theme-one/tailwind';
import configTwo from 'my-theme-two/tailwind';
export default mergeTailwindConfigs(
configOne ,
configTwo ,
{
// User config
},
)
This seems like it would be a pain to code gen though. I hope support for tailwind 4 comes soon with backwards compatibility, that would be the easiest solution, just add a Vite plugin!
I experimented with UnoCSS recently, and I think it is the best option here:
Astro Theme Provider could automatically support theme packages that use tailwind by adding the package's path to the
content
array inside the tailwind configurationThings to consider:
astro add