-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Closed
Closed
Enhancement
Copy link
Labels
Developer ExperienceIdeas about improving block and theme developer experienceIdeas about improving block and theme developer experience[Status] In ProgressTracking issues with work in progressTracking issues with work in progress[Tool] Create Block/packages/create-block/packages/create-block[Type] EnhancementA suggestion for improvement.A suggestion for improvement.
Description
What problem does this address?
When 6.7 is released, block developers will have access to wp_register_block_metadata_collection()
. We should update the default templates to include a call to that function and add build-blocks-manifest
to the generated `package.json. This will help to drive adoption of the new performance tools available.
See the full dev note:
What is your proposed solution?
Add a variation of the following to $slug.php
:
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function {{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init() {
wp_register_block_metadata_collection(
__DIR__ . '/build',
__DIR__ . '/build/blocks-manifest.php'
);
register_block_type( __DIR__ . '/build' );
}
add_action( 'init', '{{namespaceSnakeCase}}_{{slugSnakeCase}}_block_init' );
Update package.json to add the new command and also run it as a post command of build
:
"scripts": {
"build": "wp-scripts build",
"postbuild": "npm run build-blocks-manifest",
"build-blocks-manifest": "wp-scripts build-blocks-manifest",
},
Metadata
Metadata
Assignees
Labels
Developer ExperienceIdeas about improving block and theme developer experienceIdeas about improving block and theme developer experience[Status] In ProgressTracking issues with work in progressTracking issues with work in progress[Tool] Create Block/packages/create-block/packages/create-block[Type] EnhancementA suggestion for improvement.A suggestion for improvement.