@barefootjs/blade

中文文档
0.40.2发布于 2026/11/02MITTypeScriptES Module构建来源已验证近 30 天下载 1726

Laravel Blade (PHP) adapter for BarefootJS — compiles IR to .blade.php templates and ships the PHP BarefootJS rendering runtime on illuminate/view standalone

原始使用文档
文档目录3 节
  1. Template output shape
  2. PHP runtime
  3. Usage

@barefootjs/blade

Laravel Blade (PHP) adapter for BarefootJS: compiles the BarefootJS IR (JSX → IR, see spec/compiler.md) into .blade.php template files plus the client JS bundle every other adapter produces, and ships a PHP rendering runtime (php/src/) that renders those templates through illuminate/view used standalone — no Laravel application/container is required.

Near-mechanical port of @barefootjs/twig (the Twig adapter) to Blade syntax. See src/adapter/blade-adapter.ts's header comment for the full Twig↔Blade syntax-mapping table and the JS/PHP semantics divergences this port handles uniformly (truthiness, stringification, reserved-word identifier mangling, $bf->eq/$bf->neq for JS strict equality, data_get for polymorphic member/index access, and the evaluator-only higher-order- callback lowering since Blade has no lambda expression).

Template output shape

  • name: 'blade', extension: '.blade.php', templatesPerComponent: true — one .blade.php file per component, named by snake-casing the PascalCase component name (UserCard → user_card.blade.php).
  • Hydration markers (bf-s, bf-h/bf-m/bf-r, bf-p, slot/conditional comment markers, loop boundary comments) use the SAME runtime method names as every other adapter's bf.* calls, spelled as PHP method calls on the $bf variable ($bf->scope_attr(), $bf->hydration_attrs(), $bf->text_start/text_end, $bf->comment(...), …) — see spec/template-helpers.md for the shared helper contract.
  • Every text/attribute interpolation of a possibly-non-string value is routed through $bf->string(...) (or $bf->bool_str(...) for boolean-shaped values); every non-comparison condition position is routed through $bf->truthy(...); every JS ===/!== comparison routes through $bf->eq(...)/$bf->neq(...) (PHP's own ==/=== are either loose or number-representation-sensitive in ways that diverge from JS strict equality). All are pure PHP-runtime helpers — see the PHP runtime pointer below.

PHP runtime

php/src/ is a self-contained PHP package (dependencies: illuminate/view and barefootjs/runtime) implementing the engine-agnostic bf object every emitted template calls into: hydration markers, context propagation (provide_context/use_context), child-component rendering (render_child), script registration, and the JS-compatible helper library (string, bool_str, truthy, number, floor/ceil/round, array/string helpers, the *_eval evaluator helpers, spread_attrs, query, eq/neq, …). It mirrors the layering of packages/adapter-perl/lib/ (an engine-agnostic core plus a thin per-engine backend) — see spec/template-helpers.md for the semantic contract each helper must satisfy, and the package's own tests under php/tests/.

Usage

// vite.config.ts
import { defineConfig } from 'vite'
import { barefoot } from '@barefootjs/blade/vite'

export default defineConfig({
  plugins: barefoot({
    components: ['./src/components'],
    templates: './dist/templates',
  }),
})

vite build then emits .blade.php templates + client JS under templates / Vite's own build.outDir. A PHP host renders a component by constructing an illuminate/view Factory standalone (Filesystem + event Dispatcher + EngineResolver registering a blade engine over a BladeCompiler + FileViewFinder, all wired together by the Factory — see php/src/BladeBackend.php's constructor) pointed at the emitted templates, wiring in the PHP BladeBackend as the render backend. Blade's {{ }} echo (Illuminate\Support\e()) emits named HTML entity forms ("/' via ENT_QUOTES) where Perl/Go/ markupsafe emit the numeric "/' forms — see the adapter header comment for how that byte-form difference is handled.

版本与发布记录

@barefootjs/blade 共发布 78 个版本,首次发布于 2026/07/07;过去 12 个月发布了 78 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.40.2latest2026/11/027 天前
0.40.12026/10/2911 天前
0.40.02026/10/2614 天前
0.39.92026/10/2515 天前
0.39.82026/10/2119 天前
0.39.72026/10/1822 天前

关于 @barefootjs/blade 的常见问题

@barefootjs/blade 是什么?

Laravel Blade (PHP) adapter for BarefootJS — compiles IR to .blade.php templates and ships the PHP BarefootJS rendering runtime on illuminate/view standalone

如何安装 @barefootjs/blade?

在项目目录运行 npm install @barefootjs/blade,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@barefootjs/jsx(>=0.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@barefootjs/blade 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@barefootjs/blade 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@barefootjs/blade 可以商用吗?

@barefootjs/blade 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@barefootjs/blade 的下载量有多少?

根据 npm 官方下载统计,@barefootjs/blade 在 2026/10/08 – 2026/11/06 这 30 天内被下载 1,726 次,日均约 58 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@barefootjs/blade 还在维护吗?

最新版本 0.40.2 发布于 2026/11/02(7 天前);至今共发布 78 个版本,其中过去 12 个月发布了 78 个;首次发布于 2026/07/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。