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

Add multiple styles/scripts with dependencies, version, etc. in block.json and provide examples in documentation #53847

Open
troytempleman opened this issue Aug 21, 2023 · 1 comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Developer Documentation Documentation for developers

Comments

@troytempleman
Copy link

troytempleman commented Aug 21, 2023

What problem does this address?

I see on the Metadata in block.json page that its possible to add front end, editor and shared styles/scripts in block.json. I also see you can add multiple scripts for each one of these, even with a mix of file names and previously registered script handles. For example, "style": [ "file:./style.css", "example-shared-style" ]. This is great as it eliminates the need to enqueue these with wp_enqueue_script and wp_enqueue_style in PHP.

However, its not clear to me if you can add an array of dependencies, version, etc. for each script, or if you still have to use wp_enqueue_script/wp_enqueue_style when that is needed. If not, it would be even better to add this option, as each script often have their own dependencies, version, etc. It would also be nice to see an example of how to do that.

What is your proposed solution?

Add the option to add multiple styles/scripts with dependencies, version, etc. in block.json (if not already possible) and provide examples of how to do so on the Metadata in block.json page (or elsewhere).

@jordesign jordesign added [Type] Enhancement A suggestion for improvement. [Package] Style Engine /packages/style-engine labels Aug 22, 2023
@gziolo gziolo added [Feature] Block API API that allows to express the block paradigm. [Type] Developer Documentation Documentation for developers and removed [Package] Style Engine /packages/style-engine [Type] Enhancement A suggestion for improvement. labels Aug 27, 2023
@gziolo gziolo mentioned this issue Sep 5, 2023
58 tasks
@gaambo
Copy link
Contributor

gaambo commented Sep 14, 2023

That's a great point and it's the reason why I mostly register my block assets via wp_register_script and then only pass the handle in block.json: So I can define dependencies.
But I guess it's hard to think of a "simple" schema to define those in JSON.
I guess using @wordpress/scripts simplifies that a bit, because It creates an .asset.php file which has the dependencies and a version. In some old projects I'm still building all assets via Gulp and don't have that - so I manually define the dependencies and create a version based on filemtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

No branches or pull requests

4 participants