Tailwind 4 support for consuming apps - core-components ships a Tailwind-3-only plugin
#3313
bernie-nyc
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Description
Apps that embed
@evidence-dev/core-componentsin their own build (not the Evidenceapp framework) currently can't move to Tailwind CSS 4.
core-components@5.4.2depends on
@evidence-dev/tailwind@3.1.4, which is built on the Tailwind 3 JS-pluginmodel (config-file
plugins: [...],tw-colors,tailwindcss@3.4.18). Tailwind 4 isCSS-first and compiles each imported CSS module in isolation, which surfaces two hard
incompatibilities in Evidence's published
dist. Both are fixable without changingany Evidence runtime behavior.
I've built a working, dependency-free compatibility bridge for our own app and would like
to contribute it (or the equivalent) upstream. Details and a reference implementation below.
Environment
@evidence-dev/core-components@5.4.2(latest release)@evidence-dev/tailwind@3.1.4→tailwindcss@3.4.18,tw-colors@^3.3.2tailwindcss@^4.3.3+@tailwindcss/viteWhat problem would this solve?
Under Tailwind 4 the app build fails, and even if it didn't, Evidence's colors wouldn't
render. Two distinct causes:
1. Raw
@applyin compiled CSS modules → hard build failureTwo stylesheets shipped in
distuse bare@applywith Evidence utilities and Tailwindbuilt-ins:
dist/unsorted/ui/QueryViewerSupport/prismtheme.css-@apply font-mono;,@apply text-base-content-muted;dist/organisms/layout/header/SearchButton.css-@apply bg-base-100 border-base-300 hover:bg-base-200/40 … font-sans …;,@apply text-base-content-muted;They're imported directly by components (e.g.
Prismjs.sveltedoesimport './prismtheme.css'). Tailwind 3 processed the whole tree in one PostCSS pass, so theseresolved. Tailwind 4 compiles each imported CSS module in isolation and can't see the
utility/theme surface, so the build dies with:
Tailwind 4's fix for this pattern is an
@referencedirective at the top of such modules.2. Compiled CSS references
--twc-*variables that only Evidence's TW3 plugin definesEvidence's compiled CSS reads
tw-colorschannel variables directly, e.g. inModal.svelte:and throughout
distin the Tailwind-3 opacity-fallback form:These
--twc-<token>variables (and the--tw-*-opacitydefaults the fallbacks lean on)are emitted at Evidence's own build time by
@evidence-dev/tailwind'screateThemes(tw-colors) +createVarsForColorsplugins. A consuming app on Tailwind4 doesn't run those plugins, so the variables are undefined and every Evidence surface
that uses them renders transparent/incorrect.
How should it work?
Proposed solution
Ship a Tailwind 4 path alongside the existing Tailwind 3 one, mirroring how
@evidence-dev/tailwindis already structured (it already exports a./vite-plugin):@themeCSS) reproducing Evidence's color/theme surface:--color-<token>entries sobg-*/text-*/border-*utilities exist, routed through--twc-<token>channels so they theme-switch;--twc-<token>"H S% L%"channel values per theme (the exact output ofresolveTwcConfig/createVarsForColors), bound to:root/[data-theme=…];[data-theme="dark"]as an@custom-variant;--tw-*-opacity: 1defaults so the compiled TW3 opacity fallbacks resolve;@source inline(...)safelist over the token surface.@referenceinto Evidence's raw-@applydistCSSmodules (the
prismtheme.css/SearchButton.cssclass above) - the same shape as theexisting
@evidence-dev/tailwind/vite-plugin.Because the
--twc-*values are derivable from Evidence's existing theme pipeline(
buildThemes → resolveTwcConfig), the preset can be generated from a user'sevidence.configrather than hardcoded, so custom themes keep working.Reference implementation
I built exactly this as a standalone package (
evidence-tailwind4) with zero coupling toour host app, specifically so it can lift upstream:
preset.css-@themerouted through--twc-*, per-theme channel values generated fromEvidence's default theme, dark
@custom-variant, fonts,--tw-*-opacitydefaults, safelist.vite-plugin.js- injects@reference "tailwindcss"+ the preset into Evidence's@applyCSS modules (enforce: 'pre', so it runs before@tailwindcss/vite).dark variant,
--twc-*routing, and both-theme channels.Verification: full production build green; real-browser computed styles show Evidence's
exact default palette in light and dark, with both app utilities and Evidence's baked
hsl(var(--twc-*) / a)references switching on[data-theme](e.g.
bg-primary→#2563eblight /#3b82f6dark;bg-base-100→ white /rgb(9,9,11)).Questions for maintainers
./tailwind4/./preset.css+./vite-pluginexport on@evidence-dev/tailwind(guarded so the TW3 path is untouched), or as a separate package?evidence.configat build time vs.shipped static + overridable? (I lean generated, reusing
resolveTwcConfig.)diststylesheets self-referencing (adding@referenceat Evidence's build time) so the Vite plugin becomes unnecessary for the
@applycase?Happy to open a PR against whichever shape you prefer.
All reactions