Download the PHP package daikazu/asset-cleaner without Composer
On this page you can find all versions of the php package daikazu/asset-cleaner. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download daikazu/asset-cleaner
More information about daikazu/asset-cleaner
Files in daikazu/asset-cleaner
Package asset-cleaner
Short Description Clean unused assets from your Laravel app.
License MIT
Homepage https://github.com/daikazu/asset-cleaner
Informations about the package 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
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
- 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 (
<x-component>,@component(),view(), etc.) - Separate backup directory for component files
- Protected patterns for layout components
Installation
Install the package via Composer:
Publish the config file:
Quick Start
Image Asset Cleaner
Step 1: Scan for unused assets
This scans your project and generates an unused-assets.json manifest in your project root.
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.
Step 3: Clean up
This deletes the files listed in the manifest (with backup by default).
Blade Component Cleaner
Step 1: Scan for unused components
This scans your project for Blade components and generates an unused-components.json manifest.
Step 2: Review the manifest
Open unused-components.json and review the list of unused components. Remove any entries for components you want to keep.
Step 3: Clean up
This deletes the components listed in the manifest. For class-based components, both the PHP class and the Blade view are deleted.
Commands
Image Asset Commands
asset-cleaner:scan
Scan for unused image assets and generate a manifest.
asset-cleaner:clean
Delete unused assets based on the manifest or perform a one-shot cleanup.
Blade Component Commands
blade-cleaner:scan
Scan for unused Blade components and generate a manifest.
blade-cleaner:clean
Delete unused components based on the manifest or perform a one-shot cleanup.
Configuration
Programmatic Usage
Image Asset Cleaner
Blade Component Cleaner
How It Works
Image Asset Detection
-
Scanning: The package recursively scans configured directories for files matching image extensions.
-
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)
- Full relative path (
-
Manifest Generation: Unused assets are written to a JSON manifest that you can review and edit.
- Deletion: Files are deleted based on the manifest, with optional backup to
.asset-cleaner-backup/.
Blade Component Detection
-
Scanning: The package scans for:
- Anonymous components in
resources/views/components/ - Class-based components in
app/View/Components/
- Anonymous components in
-
Component Name Derivation:
- Anonymous:
resources/views/components/forms/input.blade.php→forms.input→<x-forms.input> - Class-based:
App\View\Components\Forms\TextInput→forms.text-input→<x-forms.text-input>
- Anonymous:
-
Reference Detection: For each component, the package searches for:
- Component tags:
<x-component-name>,<x-component-name /> - Nested components:
<x-forms.input> - Dynamic components:
<x-dynamic-component component="name"> - Legacy directive:
@component('components.name') - Direct view calls:
view('components.name') - Class registrations:
Blade::component()
- Component tags:
- Deletion: For class-based components, both the PHP class and Blade view are deleted together.
Best Practices
-
Always review the manifest before running clean, especially the first time.
-
Use
--dry-runto preview changes before committing to deletion. -
Keep backups enabled until you're confident in the results.
-
Add to
.gitignore: -
Protect critical assets by adding patterns to
protected_patternsin the config. -
Run after major refactors when you've removed features or redesigned pages.
- Protect layout components - they may not appear to be used if they're only referenced via
@extends.
Limitations
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
- Dynamic component names (e.g.,
<x-dynamic-component :component="$var">) 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
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Mike Wall
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of asset-cleaner with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0