Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/tailwind-merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,22 @@
*/

'blade_directive' => 'twMerge',

/*
|--------------------------------------------------------------------------
| Cache
|--------------------------------------------------------------------------
|
| Configure caching for Tailwind Merge. Enabling cache will store processed
| class lists using your chosen cache store, which may reduce processing
| time in some environments. However, in high-traffic or development environments,
| disabling cache can actually reduce the number of Cache server or database calls
| and improve performance. Adjust these settings based on your application's needs
| and infrastructure.
*/

'cache' => [
'enabled' => env('TAILWIND_MERGE_CACHE_ENABLED', true),
'store' => env('TAILWIND_MERGE_CACHE_STORE'), // use Laravel's default
],
];
15 changes: 11 additions & 4 deletions src/TailwindMergeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ class TailwindMergeServiceProvider extends BaseServiceProvider
{
public function register(): void
{
$this->app->singleton(TailwindMergeContract::class, static fn (): TailwindMerge => TailwindMerge::factory()
->withConfiguration(config('tailwind-merge', []))
->withCache(app('cache')->store()) // @phpstan-ignore-line
->make());
$singletonClosure = static function (): TailwindMerge {
$twm = TailwindMerge::factory()->withConfiguration(config('tailwind-merge', []));

if (config('tailwind-merge.cache.enabled')) {
$twm->withCache(app('cache')->store(config('tailwind-merge.cache.store'))); // @phpstan-ignore-line
}

return $twm->make();
};

$this->app->singleton(TailwindMergeContract::class, $singletonClosure);

$this->app->alias(TailwindMergeContract::class, 'tailwind-merge');
$this->app->alias(TailwindMergeContract::class, TailwindMerge::class);
Expand Down