PHPackages                             felixdorn/klass - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. felixdorn/klass

ActiveLibrary[Templating &amp; Views](/categories/templating)

felixdorn/klass
===============

Extract dynamic classes in your Blade components

03PHP

Since May 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/felixdorn/klass)[ Packagist](https://packagist.org/packages/felixdorn/klass)[ RSS](/packages/felixdorn-klass/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Klass for Laravel
=================

[](#klass-for-laravel)

Klass extracts your dynamic classes in your Blade components to a file that PurgeCSS can process.

[![Tests](https://github.com/felixdorn/klass/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/felixdorn/klass/actions/workflows/tests.yml)[![Formats](https://github.com/felixdorn/klass/actions/workflows/formats.yml/badge.svg?branch=master)](https://github.com/felixdorn/klass/actions/workflows/formats.yml)[![Version](https://camo.githubusercontent.com/4e02178b5b6e983d5fe6d23f71d8051079b1b0c5a581aa96ac50f61fe9c84ea2/68747470733a2f2f706f7365722e707567782e6f72672f66656c6978646f726e2f6b6c6173732f76657273696f6e)](//packagist.org/packages/felixdorn/klass)[![Total Downloads](https://camo.githubusercontent.com/56287406d7e656ca5c37cddbf6cde25a306e70471aa82204b780ebae1397dedc/68747470733a2f2f706f7365722e707567782e6f72672f66656c6978646f726e2f6b6c6173732f646f776e6c6f616473)](//packagist.org/packages/felixdorn/klass)[![License](https://camo.githubusercontent.com/a3a47aaa5ee7631e54fd7b45f950e24ace84b30c4e8ce5057a2dbcf220258962/68747470733a2f2f706f7365722e707567782e6f72672f66656c6978646f726e2f6b6c6173732f6c6963656e7365)](//packagist.org/packages/felixdorn/klass)

Installation
------------

[](#installation)

> Requires [PHP 8.0.0+](https://php.net/releases)

You can install the package via composer:

```
composer require felixdorn/klass
```

Usage
-----

[](#usage)

```
// app/View/Components/Button.php
class Button extends Component {
    public string $color;

    public function __construct(string $color = 'blue') {
        $this->color = $color;
    }

    public function render() {
        return view('components.button');
    }
}
```

```

    {{ $slot }}

```

```

```

```
php artisan klass:extract
```

```
// storage/framework/extracted-classes.txt
bg-red-500 bg-blue-500

```

You can now add that file to PurgeCSS, or a similar tool to include those classes in your final CSS build.

Configuration
-------------

[](#configuration)

You can publish the config file with:

```
php artisan vendor:publish --provider="Felix\\Klass\\KlassServiceProvider" --tag="klass-config"
```

This is the contents of the published config file:

```
return [
    'components_paths' => [
        resource_path('views/components'),
        base_path('vendor'),
    ],

    'views_paths' => [
        resource_path('views'),
    ],

    'output' => base_path('storage/framework/extracted-classes.txt'),
];
```

Tailwind &amp; JIT compilation
------------------------------

[](#tailwind--jit-compilation)

Klass works well with the old Tailwind workflow aka use a build with a ton of classes in development and then remove all of the unused classes in production. However, recently, Tailwind got a JIT compiler to have a production-like css in development.

Klass could work quite easily with the JIT compiler. At compile time, `php artisan klass:extract` should be called but I have yet to figure out how to do that in a smart way.

Livewire
--------

[](#livewire)

Blade components used in a Livewire component are analyzed. However, we do not support Livewire components in itself. I have no plans to support it before traditional Blade components edge cases are resolved. I'd merge a PR adding support for it, if you feel like contributing.

Testing
-------

[](#testing)

```
composer test
```

**Klass** was created by **[Félix Dorn, 16 year old maker](https://twitter.com/afelixdorn)** under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/eeca3822ab1a1281e77e0c4f7bdb671c840417def9884107629952224ce42eb0?d=identicon)[felixdorn](/maintainers/felixdorn)

---

Top Contributors

[![felixdorn](https://avatars.githubusercontent.com/u/55788595?v=4)](https://github.com/felixdorn "felixdorn (32 commits)")

---

Tags

package

### Embed Badge

![Health badge](/badges/felixdorn-klass/health.svg)

```
[![Health](https://phpackages.com/badges/felixdorn-klass/health.svg)](https://phpackages.com/packages/felixdorn-klass)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
