Download the PHP package stamat/tailwind-merge-php without Composer
On this page you can find all versions of the php package stamat/tailwind-merge-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stamat/tailwind-merge-php
More information about stamat/tailwind-merge-php
Files in stamat/tailwind-merge-php
Package tailwind-merge-php
Short Description Merge Tailwind CSS v4 class lists without style conflicts — a fast, dependency-free PHP port of tailwind-merge. Laravel-ready.
License MIT
Informations about the package tailwind-merge-php
tailwind-merge-php
Merge Tailwind CSS class lists without style conflicts — a fast, independent PHP port of dcastil/tailwind-merge, ported directly from the JS source and not a fork of any existing PHP package.
If you are building a complex UI — you should componentize. And if you are using Tailwind and componentizing — you need Tailwind Merge.
Laravel glue ships in the box, so it's ready for Laravel too. The name tailwind-merge-php is deliberate: this is a framework-agnostic PHP package first, and a Laravel plugin second.
- Tailwind CSS v4 only. (to v4.3) No legacy v3 config (no custom separators, TW3 theme keys, etc.). The v3-style leading
!important modifier is still parsed, matching upstream. - Fast. Class-map trie built once per instance, native string functions on the hot path, in-process LRU result cache. Roughly 50× faster than
gehrisandro/tailwind-merge-phpon the same real-world class lists even with the cache disabled, far more with a warm cache (note: that port targets Tailwind v3, this one v4). The benchmark itself was deliberately removed from the repo — it isn't part of the shipped package or the test contract. - Defensive.
strict_types, final classes, PHPStan level max, invalid config keys and non-string class list entries rejected withInvalidArgumentException. - Test-based. The behavior contract is the upstream JS test suite: 371 tests / ~1,900 assertions, including 323 merge cases extracted from and verified against the real
tailwind-mergenpm package v3.6.0 (which targets Tailwind CSS v4).
Usage
Custom config
Laravel
Framework glue ships in the box and is auto-discovered — no manual provider
registration. Install illuminate/support (already present in any Laravel app).
The container binds a single shared, configured instance. In a Laravel app,
always resolve through the facade or container (as above) — not
TailwindMerge::instance(). That static helper returns a separate instance
built from the default config, ignoring anything you set in
config/tailwind-merge.php (e.g. prefix, cacheSize), so the two can merge
differently.
Publish the config to tune cacheSize, prefix, extend and override:
Development
src/DefaultConfig.php is generated from the upstream JS package — do not edit by hand.
The upstream version is pinned in bin/package-lock.json and stamped into the generated
file header; bump bin/package.json to move it. CI regenerates and fails on drift.
tests/Fixtures/merge-cases.json holds merge cases extracted from the upstream test
suites and verified against the real JS implementation.
Disclaimer
This repo was built with AI — specifically Claude Fable 5 — as a model test, with explicit instructions to follow best practices such as strict test-driven and defensive coding.
I know there are several PHP ports of tailwind-merge, but after reviewing them, I've seen the areas they could be improved upon, so I decided to synthesize my own. I do need it for a project or two.
The main improvement is that the tests come straight from upstream and are treated as law: the behavior contract is the JS tailwind-merge test suite itself, not a hand-picked subset. If upstream and this port disagree, upstream is right and the port is the bug.
With 🫀 @stamat
License
MIT, @stamat. Ported from tailwind-merge (MIT, © Dany Castillo).