-
Notifications
You must be signed in to change notification settings - Fork 1
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
Building block assets #17
Comments
@scottblackburn this is related to enqueuing of assets per-block, would be interested to know what you think |
Hey @g-elwell and @ampersarnie I was going to open a new issue for Happy to discuss any of this further though as a lot of this is untested/theoretical as was just putting down some ideas around it. Description
The current supported assets via
More information and definitions of the above can be found here. Currently I think the only way to use Multiple
This will also lead to the maintenance of the required checks around any defined asset constants used from I propose that we look into modifying the build tools to also check for A basic example of a folder structure of
built to;
These folder structures would be duplicated for as many blocks as necessary. Each blocks UsageDepending on changes and with the new structure we could use 1. Using registered script/style handles in
|
Thanks for sharing @chrishbite ! This issue would also be implemented by #117 which was added recently and is something we can hopefully explore sooner rather than later. The additional context you've added here will also be relevant in discussions around how we approach that issue |
I've been looking into block themes and how blocks are going to be built in WP going forward, there's some interesting developments in enqueuing assets on a per-block basis.
For example, if you register a block using
block.json
you can define its script/style assets there - including separate ones for editor/frontend bundles. WordPress will only load the assets if the block is present on the current page, so it's a pretty cool optimisation and has already landed in core.Since these build tools support multiple entrypoints, it's possible to get this working, but I feel like treating a block more as a 'project' could be an overall better approach, especially since a theme or plugin might have several blocks each featuring multiple entrypoints.
This could also enable block code to live together, rather than the current requirement where JS and PHP code for the same block need to be managed in separate locations, perhaps something like this (you'd potentially have multiples of these inside a specific plugin/theme):
The end result should be that you just need to require the
index.php
file in order for your block to work, since it usesblock.json
to register the block, and theblock.json
tells it which scripts/styles to enqueue. I haven't tested this fully, since I wanted to see what you all think about whether it woulda good idea to integrate this with the build tools?I'm guessing either another folder would need to be scanned for projects, or we'd consider adding a config so you can tell the build tools which projects it should be looking for explicitly...
Ref:
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/
The text was updated successfully, but these errors were encountered: