blaze-optimize
Set up and optimize Blade component rendering with Blaze. Use when installing Blaze, optimizing components, or configuring @blaze directives and strategies.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 54
- Forks
- 22
01 前言 Front Matter
- name
- blaze-optimize
- license
- MIT
- metadata
- { "author": "livewire" }
- description
- Set up and optimize Blade component rendering with Blaze. Use when installing Blaze, optimizing components, or configuring @blaze directives and strategies.
02 资源文件 2
- 参考文档references/advanced-optimization.md8.1 KB
- 参考文档references/folding-safety.md6.3 KB
03 SKILL.md 正文
Blaze Optimize
Blaze compiles anonymous Blade components into optimized PHP functions, significantly reducing rendering overhead.
EXECUTE steps 1–5 IMMEDIATELY without asking the user. Do NOT prompt for confirmation or offer choices — these are safe, low-risk changes. Only pause at step 6 to present the summary.
1. Install
Check composer.json for livewire/blaze. If missing:
composer require livewire/blaze:^1.0
2. Codebase Scan
Quick scan before making changes. Do not read individual component files.
Check:
composer.jsonforlivewire/flux,livewire/flux-pro,livewire/livewire,livewire/blaze- Component count: glob
resources/views/components/**/*.blade.php - Directory structure under
resources/views/components/ - Custom component paths: grep providers for
anonymousComponentPathoranonymousComponentNamespace— these register additional component directories that also need optimization app/Providers/AppServiceProvider.phpfor existingBlaze::optimize()calls.envforBLAZE_ENABLEDorBLAZE_DEBUG
Flux detected
Blaze optimizes Flux components automatically. No configuration needed — just install the package. If the project also has its own anonymous components, continue with setup for those.
Already configured
Describe the current setup. Do not make further changes unless the user asks.
3. Compatibility Check
Before enabling Blaze for a directory, grep its components for patterns Blaze does not support. Exclude any components or directories that match:
| Pattern | What to grep for | Why |
|---|---|---|
| Class-based components | PHP class files in app/View/Components/ that correspond to component directories |
Blaze only supports anonymous components |
$component variable |
$component |
Not available in Blaze |
| View composers/creators | View::composer( or View::creator( in app/Providers/ targeting component views |
These do not fire for Blaze components |
View::share() variables |
View::share( in providers, then grep components for those variable names |
Shared variables are not auto-injected — must use $__env->shared('key') instead |
Rendered via view() |
view('components. or View::make('components. |
Blaze components can only be rendered using component tags (<x-...>) |
Report any incompatible components so they can be excluded in the next step.
4. Enable Compilation
Add to AppServiceProvider::boot():
use Livewire\Blaze\Blaze;
public function boot(): void
{
Blaze::optimize()->in(resource_path('views/components'));
}
Include any custom component paths found in step 2:
Blaze::optimize()
->in(resource_path('views/components'))
->in(resource_path('views/other-components'));
Exclude any directories or files flagged in the compatibility check:
Blaze::optimize()
->in(resource_path('views/components'))
->in(resource_path('views/components/legacy'), compile: false) // directory
->in(resource_path('views/components/complex-widget.blade.php'), compile: false); // single file
5. Enable Debug + Clear Views
Set BLAZE_DEBUG=true in .env so trace data is collected when the user browses pages. Then clear cached views:
php artisan view:clear
6. Summary Report
Keep the summary SHORT and concise. A few bullet points, no tables, no per-directory breakdowns. Only mention what changed and what was excluded. Example:
- Compilation enabled for
resources/views/components(72 components) - No incompatible components found
BLAZE_DEBUG=trueset in.env
If components were excluded, list them briefly. If there are refactors to suggest, add:
- Suggested refactors:
- Class-based components — convert to anonymous so Blaze can compile them
- View::share / composer / creator reliance — pass data via props instead, or use
$__env->shared('key')
Then present the advanced optimization options. Use the SAME formatting as written below — numbered options with a clear ask for the user to pick one. Only include Option 3 if the compatibility check found refactors to suggest. If there are no refactors, omit Option 3 entirely. Mark Option 3 as RECOMMENDED when present, otherwise mark Option 1 as RECOMMENDED.
When there are refactors to suggest:
Want to go further?
Option 1 — Trace-based optimization Browse your app with debug mode enabled (already active), make sure to visit the slow or component-heavy pages, then tell me you're done. I'll analyze the trace data and apply targeted memo/fold optimizations to the slowest components.
Option 2 — Code analysis Full codebase audit without trace data. WARNING: significantly more token-intensive, results are speculative, and incorrect optimizations can break components. Requires thorough testing.
Option 3 — Apply refactors first (RECOMMENDED) Apply the suggested refactors to bring excluded components into Blaze compilation. I'll come back to these options when done.
Reply 1, 2, or 3 when ready (or skip if you don't need advanced optimization).
When there are NO refactors:
Want to go further?
Option 1 — Trace-based optimization (RECOMMENDED) Browse your app with debug mode enabled (already active), make sure to visit the slow or component-heavy pages, then tell me you're done. I'll analyze the trace data and apply targeted memo/fold optimizations to the slowest components.
Option 2 — Code analysis Full codebase audit without trace data. WARNING: significantly more token-intensive, results are speculative, and incorrect optimizations can break components. Requires thorough testing.
Reply 1 or 2 when ready (or skip if you don't need advanced optimization).
STOP
You are done. Do NOT proceed with advanced optimization (memoization, folding) unless the user explicitly asks for it. When they do, read references/advanced-optimization.md for instructions.
04 同仓库更多 Skills
tailwindcss-development
Always invoke when the user's message includes 'tailwind' in any form. Also invoke for: building responsive grid layouts (multi-column card grids, product grids), flex/grid page structures (dashboards with sidebars, fixed topbars, mobile-toggle navs), styling UI components (cards, tables, navbars, pricing sections, forms, inputs, badges), adding dark mode variants, fixing spacing or typography, and Tailwind v3/v4 work. The core use case: writing or fixing Tailwind utility classes in HTML templates (Blade, JSX, Vue). Skip for backend PHP logic, database queries, API routes, JavaScript with no HTML/CSS component, CSS file audits, build tool configuration, and vanilla CSS.
pulse-development
Handles Laravel Pulse setup, configuration, and custom card development. Activates when installing Pulse; configuring the dashboard or authorization gate; setting up recorders and filtering; building custom Livewire cards; optimizing with Redis ingest or sampling; or when the user mentions /pulse, pulse:check, pulse:work, Pulse::record(), or application monitoring.
pest-testing
Use this skill for Pest PHP testing in Laravel projects only. Trigger whenever any test is being written, edited, fixed, or refactored — including fixing tests that broke after a code change, adding assertions, converting PHPUnit to Pest, adding datasets, and TDD workflows. Always activate when the user asks how to write something in Pest, mentions test files or directories (tests/Feature, tests/Unit, tests/Browser), or needs browser testing, smoke testing multiple pages for JS errors, or architecture tests. Covers: test()/it()/expect() syntax, datasets, mocking, browser testing (visit/click/fill), smoke testing, arch(), Livewire component tests, RefreshDatabase, and all Pest 4 features. Do not use for factories, seeders, migrations, controllers, models, or non-test PHP code.
medialibrary-development
Build and work with spatie/laravel-medialibrary features including associating files with Eloquent models, defining media collections and conversions, generating responsive images, and retrieving media URLs and paths.
livewire-development
Use for any task or question involving Livewire. Activate if user mentions Livewire, wire: directives, or Livewire-specific concepts like wire:model, wire:click, wire:sort, or islands, invoke this skill. Covers building new components, debugging reactivity issues, real-time form validation, drag-and-drop, loading states, migrating from Livewire 3 to 4, converting component formats (SFC/MFC/class-based), and performance optimization. Do not use for non-Livewire reactive UI (React, Vue, Alpine-only, Inertia.js) or standard Laravel forms without Livewire.
laravel-best-practices
Apply this skill whenever writing, reviewing, or refactoring Laravel PHP code. This includes creating or modifying controllers, models, migrations, form requests, policies, jobs, scheduled commands, service classes, and Eloquent queries. Triggers for N+1 and query performance issues, caching strategies, authorization and security patterns, validation, error handling, queue and job configuration, route definitions, and architectural decisions. Also use for Laravel code reviews and refactoring existing Laravel code to follow best practices. Covers any task involving Laravel backend PHP code patterns.