Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLANET-7519: Guestbook block refactoring to block.json #2286

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lithrel
Copy link
Contributor

@lithrel lithrel commented May 17, 2024

Ref: https://jira.greenpeace.org/browse/PLANET-7519

This is a demo for block refactoring, following Gutenberg structure. It allows WordPress to handle assets loading automatically.

This PR has multiple issues, due to the packages and webpack versions being a lot older than what Gutenberg currently uses. In particular, we can't update wordpress/scripts higher because of npm version and webpack version.

As a hack, we copy some functions from the scripts package in a specific webpack config file dedicated to those blocks.
We also attempt to make the main webpack config independent of wordpress/scripts, to try help with future packages/webpack updates

Load blocks in PHP using Blocks\Register::registerFromAssets('foldername');
Run npm run build:blocks to build blocks converted to block.json structure.
Assets are loaded automatically by WordPress when it detects a block in content.
To test Guestbook locally, run the npm block command, disable the planet4-gutenberg-blocks plugin, use a Guestbook block and check that:

  • editor loads a assets/build/blocks/guestbook/index.js
  • frontend loads a assets/build/blocks/guestbook/viewScripts.js

Cf. documentation for autoloaded scripts

Ref: https://jira.greenpeace.org/browse/PLANET-7519

This is a demo for block refactoring, following Gutenberg structure.
It allows WordPress to handle assets loading automatically.

This PR has multiple issues, due to the packages and webpack versions
being a lot older than what Gutenberg currently uses.
In particular, we can't update wordpress/scripts higher because of
PostCss package, npm version, webpack version.
@lithrel lithrel self-assigned this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant