Build plugin with multiple blocks

I have created a plugin using the default “to-to-list” that WordPress provides npx @wordpress/create-block todo-list, Is there a way to convert to work with multiple blocks?

Basically I created “todo-list” by default, then created a new directory blocks/todo-list and moved the src/build folders there. then edited todo-list.php from the register_block_type directory /build To /blocks/todo-list/build, Then updated package.json start/build script for:

"build": "wp-scripts build blocks/todo-list/src/index.js --output-path=blocks/todo-list/build",
"start": "wp-scripts start blocks/todo-list/src/index.js --output-path=blocks/todo-list/build"

The file structure would be:

- blocks
  - todo-list
    - build
    - src
  - block-2
    - build
    - src
- node_modules
- package-lock.json
- package.json
- readme.txt
- todo-list.php

I did npm run build And don’t look at the Todo List as a block. I haven’t added any block-2 yet, but that will be it. Can this structure work?

I created a quick repo to show the structure and files todo-list. Thanks for any help!

Leave a Comment