PHPackages                             daikazu/asset-cleaner - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. daikazu/asset-cleaner

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

daikazu/asset-cleaner
=====================

Clean unused assets from your Laravel app.

v1.4.0(3mo ago)2223MITPHPPHP ^8.4CI passing

Since Jan 3Pushed 3mo agoCompare

[ Source](https://github.com/daikazu/asset-cleaner)[ Packagist](https://packagist.org/packages/daikazu/asset-cleaner)[ Docs](https://github.com/daikazu/asset-cleaner)[ GitHub Sponsors](https://github.com/Daikazu)[ RSS](/packages/daikazu-asset-cleaner/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (6)Dependencies (24)Versions (7)Used By (0)

  ![Logo for Laravel Asset Cleaner](art/header-light.png)[![Latest Version on Packagist](https://camo.githubusercontent.com/fb81c4d864d8ea9d8072e1335098c21ffdf9da1619f549d51cda3c44fe584f22/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6461696b617a752f61737365742d636c65616e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/daikazu/asset-cleaner)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ebf2c34cd0d89720fc01080ef7b42a21d8a775961c99b6127b38733a4ec232c8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6461696b617a752f61737365742d636c65616e65722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/daikazu/asset-cleaner/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/6a1b899082dd31c494674c5aaa0b8b166ecc504ae05acd797f5f5a4fac8af36d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6461696b617a752f61737365742d636c65616e65722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/daikazu/asset-cleaner/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/248cc492386c7b6616b6a9e2dcb94fdf3d61c2dfe95cad5c22512093691fb1a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6461696b617a752f61737365742d636c65616e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/daikazu/asset-cleaner)

Laravel Asset Cleaner
=====================

[](#laravel-asset-cleaner)

This package helps you clean up your Laravel app in development by tracking down unused image files and Blade components. It scans through your codebase, finds where assets are referenced, and flags any leftover files that have no connection to the app so you can safely remove the clutter and keep things tidy.

Features
--------

[](#features)

### Image Asset Cleaner

[](#image-asset-cleaner)

- Scans configurable directories for image assets
- Searches Blade, PHP, JavaScript, Vue, CSS, and more for references
- Generates a reviewable manifest before deletion
- Supports dry-run mode to preview changes
- Automatic backup before deletion
- Protected patterns for critical assets (favicons, logos)
- One-shot "trust mode" for quick cleanup

### Blade Component Cleaner

[](#blade-component-cleaner)

- Detects unused anonymous (file-based) Blade components
- Detects unused class-based Blade components
- Deletes both PHP class and view file for class-based components
- Searches for multiple reference patterns (``, `@component()`, `view()`, etc.)
- Separate backup directory for component files
- Protected patterns for layout components

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

[](#installation)

Install the package via Composer:

```
composer require daikazu/asset-cleaner --dev
```

Publish the config file:

```
php artisan vendor:publish --tag="asset-cleaner-config"
```

Quick Start
-----------

[](#quick-start)

### Image Asset Cleaner

[](#image-asset-cleaner-1)

#### Step 1: Scan for unused assets

[](#step-1-scan-for-unused-assets)

```
php artisan asset-cleaner:scan
```

This scans your project and generates an `unused-assets.json` manifest in your project root.

#### Step 2: Review the manifest

[](#step-2-review-the-manifest)

Open `unused-assets.json` and review the list of unused assets. Remove any entries for files you want to keep.

```
{
    "generated_at": "2024-01-15T10:30:00+00:00",
    "total_scanned": 150,
    "total_unused": 12,
    "total_size_human": "2.5 MB",
    "assets": [
        {
            "path": "public/images/old-banner.jpg",
            "filename": "old-banner.jpg",
            "size_human": "450 KB"
        }
    ]
}
```

#### Step 3: Clean up

[](#step-3-clean-up)

```
php artisan asset-cleaner:clean
```

This deletes the files listed in the manifest (with backup by default).

### Blade Component Cleaner

[](#blade-component-cleaner-1)

#### Step 1: Scan for unused components

[](#step-1-scan-for-unused-components)

```
php artisan blade-cleaner:scan
```

This scans your project for Blade components and generates an `unused-components.json` manifest.

#### Step 2: Review the manifest

[](#step-2-review-the-manifest-1)

Open `unused-components.json` and review the list of unused components. Remove any entries for components you want to keep.

```
{
    "generated_at": "2024-01-15T10:30:00+00:00",
    "total_scanned": 45,
    "total_unused": 5,
    "total_size_human": "12 KB",
    "components": [
        {
            "name": "old-button",
            "view_path": "resources/views/components/old-button.blade.php",
            "is_class_based": false,
            "size_human": "1.2 KB"
        },
        {
            "name": "legacy-modal",
            "view_path": "resources/views/components/legacy-modal.blade.php",
            "is_class_based": true,
            "class_path": "app/View/Components/LegacyModal.php",
            "size_human": "3.5 KB"
        }
    ]
}
```

#### Step 3: Clean up

[](#step-3-clean-up-1)

```
php artisan blade-cleaner:clean
```

This deletes the components listed in the manifest. For class-based components, both the PHP class and the Blade view are deleted.

Commands
--------

[](#commands)

### Image Asset Commands

[](#image-asset-commands)

#### `asset-cleaner:scan`

[](#asset-cleanerscan)

Scan for unused image assets and generate a manifest.

```
# Generate manifest
php artisan asset-cleaner:scan

# Show statistics only (no manifest)
php artisan asset-cleaner:scan --stats
```

#### `asset-cleaner:clean`

[](#asset-cleanerclean)

Delete unused assets based on the manifest or perform a one-shot cleanup.

```
# Delete from manifest (with confirmation)
php artisan asset-cleaner:clean

# Preview what would be deleted
php artisan asset-cleaner:clean --dry-run

# Skip confirmation prompt
php artisan asset-cleaner:clean --force

# One-shot mode: scan and delete without manifest
php artisan asset-cleaner:clean --trust

# Combine flags for CI/CD
php artisan asset-cleaner:clean --trust --force --dry-run

# Skip backup
php artisan asset-cleaner:clean --no-backup
```

### Blade Component Commands

[](#blade-component-commands)

#### `blade-cleaner:scan`

[](#blade-cleanerscan)

Scan for unused Blade components and generate a manifest.

```
# Generate manifest
php artisan blade-cleaner:scan

# Show statistics only (no manifest)
php artisan blade-cleaner:scan --stats
```

#### `blade-cleaner:clean`

[](#blade-cleanerclean)

Delete unused components based on the manifest or perform a one-shot cleanup.

```
# Delete from manifest (with confirmation)
php artisan blade-cleaner:clean

# Preview what would be deleted
php artisan blade-cleaner:clean --dry-run

# Skip confirmation prompt
php artisan blade-cleaner:clean --force

# One-shot mode: scan and delete without manifest
php artisan blade-cleaner:clean --trust

# Combine flags for CI/CD
php artisan blade-cleaner:clean --trust --force --dry-run

# Skip backup
php artisan blade-cleaner:clean --no-backup
```

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

[](#configuration)

```
// config/asset-cleaner.php

return [
    /*
    |--------------------------------------------------------------------------
    | Image Asset Cleaner Configuration
    |--------------------------------------------------------------------------
    */

    // Directories to scan for image assets
    'scan_paths' => [
        'public',
        'resources',
    ],

    // File extensions considered as images
    'image_extensions' => [
        'jpg', 'jpeg', 'png', 'gif', 'svg',
        'webp', 'ico', 'bmp', 'tiff', 'avif',
    ],

    // Directories to search for references
    'search_paths' => [
        'app',
        'resources',
        'routes',
        'config',
        'database',
    ],

    // File types to search for image references
    'search_extensions' => [
        'php', 'blade.php',
        'js', 'jsx', 'ts', 'tsx', 'vue', 'svelte',
        'css', 'scss', 'sass', 'less',
        'json', 'yaml', 'yml',
        'md', 'mdx',
    ],

    // Patterns to exclude from scanning
    'exclude_patterns' => [
        '**/node_modules/**',
        '**/vendor/**',
        '**/.git/**',
    ],

    // Protected files (never marked as unused)
    'protected_patterns' => [
        '**/favicon.ico',
        '**/favicon.png',
        '**/apple-touch-icon.png',
        '**/logo.*',
    ],

    // Manifest file location
    'manifest_path' => 'unused-assets.json',

    // Backup files before deletion
    'backup_before_delete' => true,
    'backup_path' => '.asset-cleaner-backup',

    /*
    |--------------------------------------------------------------------------
    | Blade Component Cleaner Configuration
    |--------------------------------------------------------------------------
    */

    'blade_cleaner' => [
        // Directories for anonymous components
        'anonymous_paths' => [
            'resources/views/components',
        ],

        // Directories for class-based components
        'class_paths' => [
            'app/View/Components',
        ],

        // Directories to search for component references
        'search_paths' => [
            'resources/views',
            'app',
            'routes',
            'config',
        ],

        // File types to search
        'search_extensions' => [
            'blade.php',
            'php',
        ],

        // Patterns to exclude
        'exclude_patterns' => [
            '**/vendor/**',
            '**/node_modules/**',
        ],

        // Protected components (never marked as unused)
        'protected_patterns' => [
            'layout',
            'layouts.*',
            'app-layout',
        ],

        // Manifest file location
        'manifest_path' => 'unused-components.json',

        // Backup directory (separate from image assets)
        'backup_path' => '.blade-cleaner-backup',
    ],
];
```

Programmatic Usage
------------------

[](#programmatic-usage)

### Image Asset Cleaner

[](#image-asset-cleaner-2)

```
use Daikazu\AssetCleaner\Facades\AssetCleaner;

// Get all image assets
$assets = AssetCleaner::scan();

// Find unused assets
$unused = AssetCleaner::findUnused();

// Get statistics
$stats = AssetCleaner::getStatistics();
// Returns: ['total' => 150, 'unused' => 12, 'used' => 138, ...]

// Generate manifest
AssetCleaner::generateManifest();

// Clean from manifest
$result = AssetCleaner::cleanFromManifest();

// One-shot cleanup
$result = AssetCleaner::cleanAll();

// Dry run
$result = AssetCleaner::cleanAll(dryRun: true);
```

### Blade Component Cleaner

[](#blade-component-cleaner-2)

```
use Daikazu\AssetCleaner\Facades\BladeCleaner;

// Get all Blade components
$components = BladeCleaner::scan();

// Find unused components
$unused = BladeCleaner::findUnused();

// Get statistics
$stats = BladeCleaner::getStatistics();
// Returns: ['total' => 45, 'unused' => 5, 'used' => 40, ...]

// Generate manifest
BladeCleaner::generateManifest();

// Clean from manifest
$result = BladeCleaner::cleanFromManifest();

// One-shot cleanup
$result = BladeCleaner::cleanAll();

// Dry run
$result = BladeCleaner::cleanAll(dryRun: true);
```

How It Works
------------

[](#how-it-works)

### Image Asset Detection

[](#image-asset-detection)

1. **Scanning**: The package recursively scans configured directories for files matching image extensions.
2. **Reference Detection**: For each image found, the package searches your codebase for references using multiple strategies:

    - Full relative path (`public/images/hero.jpg`)
    - Path without `public/` prefix (`images/hero.jpg`)
    - Filename only (`hero.jpg`)
    - Filename without extension (`hero`)
3. **Manifest Generation**: Unused assets are written to a JSON manifest that you can review and edit.
4. **Deletion**: Files are deleted based on the manifest, with optional backup to `.asset-cleaner-backup/`.

### Blade Component Detection

[](#blade-component-detection)

1. **Scanning**: The package scans for:

    - Anonymous components in `resources/views/components/`
    - Class-based components in `app/View/Components/`
2. **Component Name Derivation**:

    - Anonymous: `resources/views/components/forms/input.blade.php` → `forms.input` → ``
    - Class-based: `App\View\Components\Forms\TextInput` → `forms.text-input` → ``
3. **Reference Detection**: For each component, the package searches for:

    - Component tags: ``, ``
    - Nested components: ``
    - Dynamic components: ``
    - Legacy directive: `@component('components.name')`
    - Direct view calls: `view('components.name')`
    - Class registrations: `Blade::component()`
4. **Deletion**: For class-based components, both the PHP class and Blade view are deleted together.

Best Practices
--------------

[](#best-practices)

1. **Always review the manifest** before running clean, especially the first time.
2. **Use `--dry-run`** to preview changes before committing to deletion.
3. **Keep backups enabled** until you're confident in the results.
4. **Add to `.gitignore`**:

    ```
    unused-assets.json
    unused-components.json
    .asset-cleaner-backup/
    .blade-cleaner-backup/

    ```
5. **Protect critical assets** by adding patterns to `protected_patterns` in the config.
6. **Run after major refactors** when you've removed features or redesigned pages.
7. **Protect layout components** - they may not appear to be used if they're only referenced via `@extends`.

Limitations
-----------

[](#limitations)

### Image Assets

[](#image-assets)

- Dynamic image references (e.g., `asset($variable)`) may not be detected
- Images referenced only in the database won't be detected
- External CDN references are not tracked

### Blade Components

[](#blade-components)

- Dynamic component names (e.g., ``) with variables cannot be statically analyzed
- Components used only in tests may be flagged as unused
- Components conditionally rendered in rare scenarios may appear unused
- Livewire components are not currently supported (only standard Blade components)

For dynamic references, add the pattern to `protected_patterns` or remove entries from the manifest before cleaning.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Mike Wall](https://github.com/daikazu)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance79

Regular maintenance activity

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~14 days

Total

6

Last Release

109d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4039367?v=4)[Mike Wall](/maintainers/daikazu)[@daikazu](https://github.com/daikazu)

---

Top Contributors

[![daikazu](https://avatars.githubusercontent.com/u/4039367?v=4)](https://github.com/daikazu "daikazu (25 commits)")

---

Tags

laraveldaikazuasset-cleaner

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/daikazu-asset-cleaner/health.svg)

```
[![Health](https://phpackages.com/badges/daikazu-asset-cleaner/health.svg)](https://phpackages.com/packages/daikazu-asset-cleaner)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124603.0k](/packages/worksome-exchange)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

199.4k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

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