如何以現代方式建立 Gutenberg 區塊
何時使用: 需要自訂編輯器區塊,但不想手動搭建過時的 ESNext + webpack 腳手架。
步驟
-
描述區塊需求Build a Testimonial block: quote text, author name, author photo — edit and save views.✓ 已複製→ block.json + edit.js + save.js scaffolded, @wordpress/scripts build setup
-
新增屬性與控制項Add an alignment control and a color picker.✓ 已複製→ BlockControls / InspectorControls added correctly
-
打包並註冊Write the PHP that registers the block from block.json.✓ 已複製→ register_block_type( __DIR__ . '/build/block.json' )
結果: 一個具備正確封裝的現代 Gutenberg 區塊。
注意事項
- 缺少 i18n 包裝 — 技能包會提醒 Claude 使用 __() 和 _x() 包裝字串
搭配使用: filesystem