You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: streamline custom blocks build/lint process
- move example blocks into subfolders of src directory
- streamline build process for example blocks
- support view scripts in example blocks
- move wp-scripts to top-level package.json
- delete unnecessary dotfiles
- update instructions for using/writing custom blocks
- use same linters for plugins and other JS/SCSS
- remove formatting script of limited use
Copy file name to clipboardexpand all lines: README.md
+11-14
Original file line number
Diff line number
Diff line change
@@ -41,7 +41,6 @@ This project requires [Docker][docker] and [Node.js][node] for local development
41
41
42
42
1. Duplicate `.env.example` and rename it `.env`, changing variables [as needed](#setting-local-environment-variables)
43
43
1. Run `npm install`
44
-
1. Run `npm run plugins:install` (this is necessary for the plugin for custom blocks)
45
44
1. Either run `npm start` or run `npm run build:dev` and `npm run serve:dev` in separate terminals
46
45
1. Based on whether you have a database to import or not, do one of the following:
47
46
- Visit `https://localhost:8000/wp-admin` and run through the WordPress setup
@@ -403,34 +402,32 @@ This is a non-comprehensive list of plugins that we have found useful on other p
403
402
404
403
## Custom Blocks
405
404
406
-
We have a plugin for custom blocks called `example-blocks`, which lives in `src/plugins`. For the blocks to be available in WordPress, these steps must be taken:
405
+
We have a plugin for custom blocks called `example-blocks`, which lives in `src/plugins`. For the blocks to be available in WordPress, you must activate the "Example Blocks" plugin from the WordPress admin's plugins page.
407
406
408
-
1. Run `npm run plugins:install` to install the plugin's npm dependencies
409
-
1. Run `npm start` for local development (this runs the plugin's `npm start` command)
410
-
1. Activate the "Example Blocks" plugin from the WordPress menu
411
-
412
-
For production builds, running `npm run build:prod` will also work, outputting production bundles for the blocks.
407
+
The plugins can be built with `npm run plugins:dev` or `npm run plugins:build`, but that generally shouldn't be necessary, since those scripts are run as part of the standard `npm start` and `npm run build:prod` scripts.
413
408
414
409
### Creating a New Custom Block
415
410
416
411
Follow these steps to create a new custom block and wire it up with the normal development/build processes:
417
412
418
-
1. Create a new folder at `src/plugins/example-blocks/blocks/<block-name>`
413
+
1. Create a new folder at `src/plugins/example-blocks/src/<block-name>`
419
414
1. Either copy files from another block or manually create these files:
420
415
-`block.json`: configuration/metadata for the block
421
-
-`src/index.js`: entry point for the JS bundle
422
-
-`src/edit.js`: the component used while editing
423
-
-`src/save.js`: the component rendered on the site
424
-
-`src/editor.scss`: custom styles for the editor view
425
-
-`src/style.scss`: custom styles for the block when rendered on the site
426
-
1. Configure the custom block by updating `block.json`, namely the `name`, `title`, `icon`, and `description` fields
416
+
-`index.js`: entry point for the JS bundle
417
+
-`edit.js`: the component used while editing
418
+
-`save.js`: the component rendered on the site
419
+
-`view.js`: any JS that needs to run when the block is rendered on a non-admin page (optional)
420
+
-`editor.scss`: custom styles for the editor view
421
+
-`style.scss`: custom styles for the block when rendered on the site
422
+
1. Configure the custom block by updating `block.json`, namely the `name`, `title`, `icon`, and `description` fields. If you don't need a `view.js` file, delete the `viewScript` key.
427
423
1. Implement the edit function, which will usually be form controls corresponding to attributes that you define in `index.js`
428
424
1. Implement the save function, which will consume the attributes defined in `index.js` and render the block's desired markup
429
425
430
426
### Useful Resources
431
427
432
428
-[Create a Block Tutorial](https://developer.wordpress.org/block-editor/getting-started/create-block/)
0 commit comments