Skip to content

Add Tailwind CSS v4 compatibility - #10

Open
Shriyashzzz wants to merge 8 commits into
jln13x:mainfrom
Shriyashzzz:main
Open

Shriyashzzz wants to merge 8 commits into
jln13x:mainfrom
Shriyashzzz:main

Conversation

@Shriyashzzz

Copy link
Copy Markdown

This PR updates the plugin to work with Tailwind CSS v4, alongside continued support for v3

Got this working with Tailwind v4 while keeping v3 support intact. Summary of changes:

color.ts : swapped out the tailwindcss/lib/util/flattenColorPalette deep import (gone in v4) for a small local version of the same function.

color.ts, spread.ts, variant.ts — dropped the PluginAPI import from tailwindcss/types/config, since that path doesn't exist in v4 anymore. Added a minimal local PluginAPI type in types.ts instead.

index.ts : this was the trickier one. The .highlight::after content relied on var(--tw-content), which v3's preflight always reset to '' globally. V4 only sets that default when it sees an actual before:/after: utility in your markup — since this plugin writes its own ::after rule directly, that never happened, so the highlight silently failed to render. Fixed by just hardcoding content: ''.

tsconfig.json : updated moduleResolution/module to node16, since v4 only resolves through package.json exports maps now. Also scoped include to src/ so it stops pulling in the showcase folder.

package.json : widened the peer dep to allow v3 or v4, and added a prepare script so it actually builds when installed via git.

README : added a quick v4 section showing the @plugin (and @config) loading syntax.

Tested against Tailwind v4.3.3 w clean build, correct CSS output for all utilities, and confirmed visually in a real project.

Thanks for making this, it was a good base to work off of for my own project. Happy to adjust anything if you'd rather approach the v4 support differently

--tw-content only gets a default empty-string value in v4 when a
before:/after: utility is scanned from user content, since preflight
no longer sets it globally like it did in v3. This plugin writes
&::after { content: var(--tw-content) } directly via addUtilities,
bypassing that detection entirely, so the property stayed undefined
and the pseudo-element never rendered.

Hardcode content: '' instead of relying on Tailwind's conditional
--tw-content reset.
@vercel

vercel Bot commented Sep 12, 2026

Copy link
Copy Markdown

@Shriyashzzz is attempting to deploy a commit to the JLN Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant