How to register two blocks in the same plugin

  1. Add a subfolder in your-plugin/src with the block name
  2. Put all src files inside this folder
  3. Repeat 1 and 2 for other blocks that you want to add.

At this moment, the src folder looks like this:

enter image description here

Be careful to edit properly each block.json to give them a name, etc.

  1. replace de single block registration to multiblock in your-plugin.php file
function create_block_your_plugin_block_init() {
    register_block_type( __DIR__ . '/build/block-1' );
    register_block_type( __DIR__ . '/build/block-2' );
}
add_action( 'init', 'create_block_your_plugin_block_init' );
  1. Optionally, you can rename src folder to any name you like, for example, blocks. In that case, add --webpack-src-dir=blocks flag with the new name to package.json start script:
"scripts": {
    "build": "wp-scripts build",
    "format": "wp-scripts format",
    "lint:css": "wp-scripts lint-style",
    "lint:js": "wp-scripts lint-js",
    "packages-update": "wp-scripts packages-update",
    "plugin-zip": "wp-scripts plugin-zip",
    "start": "wp-scripts start --webpack-src-dir=blocks"
},
  1. run npm start to build build folder

That’s all.