AGENT SKILL

Blaze Blade 组件渲染优化

blaze-optimize

使用 Blaze 配置并优化 Blade 组件渲染。在安装 Blaze、优化组件,或配置 @blaze 指令与策略时使用。

License 许可
MIT
最近更新
2026-11-12
Stars
★ 6
Forks
1

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

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.json for livewire/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 anonymousComponentPath or anonymousComponentNamespace — these register additional component directories that also need optimization
  • app/Providers/AppServiceProvider.php for existing Blaze::optimize() calls
  • .env for BLAZE_ENABLED or BLAZE_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=true set 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

karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel 测试设计与评审

testing-best-practices

Laravel 测试设计与评审。适用于选择覆盖范围、测试命名或结构安排、选择断言或测试数据、隔离依赖、测试 HTTP 或安全边界、提升测试套件性能,以及评估测试价值。Pest 和 PHPUnit 语法请使用框架指南或 search-docs 查询。

测试工程师测试与质量保障
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Tailwind CSS 界面样式开发

tailwindcss-development

当用户消息以任何形式包含 'tailwind' 时必须调用。以下情形也应调用:构建响应式网格布局(多列卡片网格、商品网格)、flex/grid 页面结构(带侧边栏的仪表盘、固定顶栏、移动端切换导航)、UI 组件样式设计(卡片、表格、导航栏、定价区块、表单、输入框、徽章)、添加暗色模式变体、修复间距或排版问题,以及 Tailwind v3/v4 相关工作。核心用途:在 HTML 模板(Blade、JSX、Vue)中编写或修复 Tailwind 工具类。以下情形跳过:后端 PHP 逻辑、数据库查询、API 路由、不含 HTML/CSS 组件的 JavaScript、CSS 文件审查、构建工具配置,以及原生 CSS。

软件开发工程师前端开发与界面实现
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel Slug 与自愈 URL 开发

sluggable-development

适用场景:让 Eloquent 模型的某个字段成为 slug、为 slug 列生成迁移、切换到自愈 URL,或在路由中根据 slug 解析模型。当请求提及 slug、永久链接、spatie/laravel-sluggable 包、HasSlug 或 HasTranslatableSlug trait、#[Sluggable] 特性、SlugOptions、findBySlug、自愈 URL,或 Laravel 项目中的旧 slug 重定向时触发。内容涵盖:特性(attribute)与 trait 的选择、生成唯一 slug、配置分隔符/长度/语言/作用域/唯一性、防止 slug 被覆盖、通过 spatie/laravel-translatable 实现多语言 slug、基于 slug 列的路由模型绑定、自愈路由键、通过 SelfHealing facade 自定义 308 重定向,以及通过 config/sluggable.php 覆盖默认操作。不适用于一次性 URL 安全字符串、签名 URL,或结果不存储到模型上的 Laravel 内置 Str::slug 辅助函数。

软件开发工程师PHP/Laravel 开发
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel Pulse 监控配置与卡片开发

pulse-development

处理 Laravel Pulse 的安装配置与自定义卡片开发。在以下情形触发:安装 Pulse;配置仪表盘或授权门禁(Gate);设置记录器(recorder)与过滤规则;构建自定义 Livewire 卡片;通过 Redis 摄取或采样进行优化;或用户提及 /pulse、pulse:check、pulse:work、Pulse::record(),以及应用监控相关内容。

软件开发工程师PHP/Laravel 开发
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Laravel 媒体库开发

medialibrary-development

构建并使用 spatie/laravel-medialibrary 的功能,包括将文件与 Eloquent 模型关联、定义媒体集合与转换、生成响应式图片,以及获取媒体 URL 和路径。

软件开发工程师PHP/Laravel 开发
★ 6
karuhun-developer
karuhun-developer/template-laravel-livewire

Livewire 组件开发

livewire-development

适用于任何涉及 Livewire 的任务或问题。当用户提及 Livewire、wire: 指令,或 wire:model、wire:click、wire:sort、islands 等 Livewire 专有概念时,调用此技能。涵盖构建新组件、调试响应式问题、实时表单验证、拖放操作、加载状态、从 Livewire 3 迁移到 4、组件格式转换(SFC/MFC/基于类)以及性能优化。不适用于非 Livewire 的响应式 UI(React、Vue、仅 Alpine、Inertia.js),也不适用于不含 Livewire 的标准 Laravel 表单。

软件开发工程师PHP/Laravel 开发
★ 6