#53690 closed enhancement (fixed)
Build: Split packages and blocks to their webpack configs
Reported by: | gziolo | Owned by: | gziolo |
---|---|---|---|
Milestone: | 5.9 | Priority: | normal |
Severity: | normal | Version: | 5.9 |
Component: | Build/Test Tools | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
It aligns with the changes proposed in Gutenberg: https://github.com/WordPress/gutenberg/pull/33293.
The idea here is to split the growing webpack config into two parts:
- blocks
- packages
We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They don't work quite well with the current setup for entry points created for packages because of reasons like:
- the output path is different
- frontend scripts should not be exposed under wp globals
In general, it looks like the split is a good strategy because it nicely separates two independents parts: packages and blocks. There isn't that much overlap between configs anyway.
Add View Script support for block types
As part of the effort, this PR adds support for viewScript
in block.json
metadata file that is later translated to $view_script
in WP_Block_Type
class and exposed as view_script
from the REST API endpoint for block types.
Change History (10)
This ticket was mentioned in PR #1412 on WordPress/wordpress-develop by gziolo.
3 years ago
#1
- Keywords has-patch has-unit-tests added
3 years ago
#2
@aristath and @youknowriad – do you think we should some automated handling for the view script? At the moment it's handled manually by the File block in render_callback
. I personally think about enqueuing automatically the view script when a block is rendered and render_callback
isn't provided. We can safely assume that in such a case the block author wants to have the view script to be loaded on the frontend when the block is present in the HTML.
3 years ago
#3
@aristath and @youknowriad – do you think we should some automated handling for the view script? At the moment it's handled manually by the File block in
render_callback
. I personally think about enqueuing automatically the view script when a block is rendered andrender_callback
isn't provided. We can safely assume that in such a case the block author wants to have the view script to be loaded on the frontend when the block is present in the HTML.
Automatically enqueueing the script when the block is rendered would make sense... I don't see why we'd require manually adding it to render_callback
:+1:
3 years ago
#4
@aristath and @youknowriad – do you think we should some automated handling for the view script? At the moment it's handled manually by the File block in
render_callback
. I personally think about enqueuing automatically the view script when a block is rendered andrender_callback
isn't provided. We can safely assume that in such a case the block author wants to have the view script to be loaded on the frontend when the block is present in the HTML.
Automatically enqueueing the script when the block is rendered would make sense... I don't see why we'd require manually adding it to
render_callback
👍
Added in https://github.com/WordPress/wordpress-develop/pull/1412/commits/179116566e8a251d52b89b769033de42d4d84362. If the render_callback
is provided then it has to be explicitly handled to account for the more complex cases like with the core blocks: File and Navigation.
#5
@
3 years ago
- Owner set to gziolo
- Resolution set to fixed
- Status changed from assigned to closed
In 51501:
3 years ago
#7
Closed with https://core.trac.wordpress.org/changeset/51501.
Trac ticket: https://core.trac.wordpress.org/ticket/53690
It aligns with the changes proposed in Gutenberg: https://github.com/WordPress/gutenberg/pull/33293.
The idea here is to split the growing webpack config into two parts:
We need to add handling for JavaScript files that are going to be used with blocks on the frontend. They don't work quite well with the current setup for entry points created for packages because of reasons like
wp
globalsIn general, it looks like the split is a good strategy because it nicely separates two independents parts: packages and blocks. There isn't that much overlap between configs anyway.
## Add View Script support for block types
As part of the effort, this PR adds support for
viewScript
inblock.json
metadata file that is later translated to$view_script
inWP_Block_Type
class and exposed asview_script
from the REST API endpoint for block types.