Bash script for creating no-plugin blocks
-
I often write custom blocks for my block-themes, and I use the
npx
creation tool to do that. Because I want to include the blocks in my theme directory, and not as separate plugins, I use the ‘--no-plugin
‘ option to generate the block and perform some extra steps to get the webpack automation going. I’ve wrapped this into a Bash script here.I use it like this: I create a ‘blocks’ directory in my theme, and in there I place the Bash-script. I then create a block with
bash create-block.sh -a MajorLabel -n majorlabel -t "My First Block"
Where the ‘a’ option is the author name, the ‘n’ option is the namespace (use all lowercaps and no spaces) and ‘t’ is the block title (Remember to surround in double quotes).
It will generate a directory which you can then change into and perform
npm start
to get busy developing. All you need to do is include theindex.php
file in the block directory in yourfunctions.php
file, which you could also do withforeach ( glob( __DIR__ . '/blocks/*/index.php' ) as $file ) { require_once $file; }
- This topic was modified 1 year, 4 months ago by .
- This topic was modified 1 year, 4 months ago by .
- This topic was modified 1 year, 4 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘Bash script for creating no-plugin blocks’ is closed to new replies.