goodm4ven / tailwind-merge
Resolves conflicting TailwindCSS classes in Laravel Blade components
Fund package maintenance!
GoodM4ven
Installs: 3
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 1
pkg:composer/goodm4ven/tailwind-merge
Requires
- php: ^8.3
- illuminate/contracts: ^11.0||^12.0
- illuminate/support: ^11.0||^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
This package is auto-updated.
Last update: 2025-11-24 07:45:04 UTC
README
Dealing with TailwindCSS classes overriding can either be done with fighting important (!) classes, OR by using this package to remove the conflicting ones from the targetted component and keep the outside (passed) one instead.
Installation
You can install the package via composer:
composer require goodm4ven/tailwind-merge
Usage
It's all about the last-wins approach for consistency. Single string or multiple ones are around as arguments. You may also add them as an associative array to conditions!
- Global helper function for PHP anywhere
twMerge('text-lg text-sm'); // results in "text-sm" twMerge('sm:text-lg', 'sm:text-3xl'); // results in "sm:text-3xl" twMerge([ 'sm:text-lg py-10 px-5' => true, 'sm:text-xl' => false, 'sm:text-3xl py-5', 'sm:text-sm' => true, ]); // results in "sm:text-sm px-5 py-5"
- Resolve the merger directly (container or facade)
// Either app('tailwind-merge')->classes('last conflicting classes win'); // Or TailwindMerge::classes('last conflicting classes win');
- Attribute bag macro inside Laravel Blade components
$attributes->twMerge('last conflicting classes win', 'then last conflicting classes win');
- Blade directive for Blade views in general
@twMerge('last conflicting classes win')
Testing
composer test
Credits
- Inspired by the original package
- ChatGPT - Codex
- GoodM4ven
- All Contributors