-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Blocks: Allow customizations for assets in block.json
#46954
Comments
block.json
@jakeparis, thank you for opening this proposal. Actually, it's something that has been on the Block API roadmap #41236 for quite some time, but it didn't have a related issue. We had a related issue #40447 that would get fixed as a consequence of implementing the syntax you outlined. What's very interesting here is that nearly the same proposal was shared in https://core.trac.wordpress.org/ticket/54018#comment:5 by @ocean90. So that confirms that we were heading in the right direction to address the existing use cases. |
Big fan of this PR, ACF Blocks users often are confused by the requirement for an |
I see a relevant issue open #57234. Let’s remove this limitation if it doesn’t work great with custom blocks. |
@gziolo Sounds good to me! I think with both these PRs merged we'll have covered off most use cases! |
The other idea I shared in #57234 (comment), that instead of tweaking the format of |
Yeh, that new idea in #57234 (comment) would work too, and arguably is better than having the filter lower down the stack, so long as it prevents checking for the asset file completely if all the data is available at that point. The thing I like about this PR is that it would allow you to build a simple block, regardless of type, without having to create one additional file (and indeed, one additional filesystem read - which can be performance-expensive on value hosting), whereas the filter would require additional code to make it work. I think it's reasonable that if block.json contains the file path for the WPDefinedAsset, it should also be possible for the block.json to provide the attributes for that file. |
I left some follow-up on #57234 (comment) Overall, I think extending the
Would this even be necessary or a hindrance to exploring extending the definitions in
I love this added performance consideration and impact, and great callout @lgladdy |
I was thinking about it a bit more and I figured out that we could also combine two worlds together and optimize the way {
"viewScript": [ "file:./index.js" ]
} Instead of creating the asset file on the disk, with the proposal implemented maybe we would be able to inline it in the {
"viewScript": [ {
"file": "./index.js",
"dependencies": [],
"version": "abc123"
} ]
} For start, let's agree on the shape of the object passed to the
In practice, Is it enough for start or should it be also possible to support other arguments that can be passed to the [
|
This makes sense to me. This would be a modification to the
I think |
If at all possible, the other arguments available to |
I agreed! |
What problem does this address?
Part of #41236.
When registering a script via block.json, there is no way to specify a dependency. I understand that webpack uses a script to create
index.asset.php
with wordpress dependencies, but that doesn't work for other scripts. Our organization has some wordpress scripts which are core to our experience and relied on by other blocks/plugins. When I use block.json to register my block like"editorScript": [ "file:./index.js" ],
, there's no way to declare those core scripts as dependencies. And doing it this way:"editorScript": [ "my-core-script", "file:./index.js" ],
doesn't work either.See this discussion also: #46589
What is your proposed solution?
Allow the existing
WPDefinedAsset
shape of input to be used along with the filepath method of registered a script. It might look like this:The text was updated successfully, but these errors were encountered: