-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Documentation: Add tutorial explaining how to use the autogenerated asset file when using wp-scripts
#17423
Comments
I think the easiest way to move forward is to start using import statements in ESNext examples rather than I have no idea how much work would it require to teach Webpack to recognize @nerrad and @sirreal - do you have some other thoughts to share on this topic? |
I'm on the fence. The doc examples will work in a build system with or without wp-scripts (in a WordPress 5.0+ environment) because the globals are present. So that leads to less "gotchas" when it comes to people following the docs without using wp-scripts as a base. I think the path forward here to make sure it's clear in the documentation for the dependency extraction webpack plugin that it only extracts dependencies explicitly imported (not implicitly using the global). Since it's also included in wp-scripts automatically, it'd probably be a good idea to make it clear in that package as well? |
We can add this note to make it clear. However, I doubt it will be easy to discover for those using |
wp-scripts
I think extending the existing docs make the most sense. I have a set of materials developed for internal training that I plan to convert for public release. Just needs some buttoning up and refinement, but includes this exact example around dependencies. I'll try to get a PR ready either this week or earlier next. |
Sounds great, thank you for all the great work with tutorials 💯 |
I tend to agree with what's been said. I'd encourage use of If we were to extract dependencies from expressions like Encouraging and transitioning to explicit |
The easiest way to solve it is to expose the name of the store from the module and import it explicitly: // in @wordpress/core-data
export const STORE_NAME = 'core';
// in other places
import { STORE_NAME } from '@wordpress/core-data';
const something = wp.data.select( STORE_NAME ).... |
My example of What I want to highlight is that |
Yes, I get that but this is also an actual issue which this kind of automation uncovers. That said I totally agree that using wp.data;
wp[ 'data' ];
const x = wp; x.data;
const y = 'data'; wp[ y ];
// ...and so on |
Describe the bug
PR #15124 introduced automated script dependency files as
.deps.json
files. These should allow you to dynamically rebuild the dependencies lists that get passed towp_register_script()
. Looking at the examples in the Block Tutorial guide, I would expect that the ESNext files would generate dependency files that align with the set of dependencies in the matching function examples ( such as https://developer.wordpress.org/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/ ).Instead, you just get the default values:
Based on my testing, this appears to be because the ESNext examples use the
wp.blocks
andwp.data
global objects (instead of an import), which makes sense if those global objects are always available. However, if those global objects are only available because an existing script listed them as a dependency, then those global objects are indeed dependencies that should make it into the.deps.json
file. If, perhaps, the recommendation is to useimport
instead of the globally available objects for automated dependency resolution, then the Block Tutorial guide should be updated to match such a recommendation.Overall, this seems like either a documentation issue or an automatic dependency resolution issue, but that will depend on what you believe the best practice to be.
Thank you for all the work that you do, especially the documentation.
To reproduce
Steps to reproduce the behavior:
Expected behavior
Documentation that matches best practice recommendations and tooling results. Tooling that works with documentation examples.
Additional context
The text was updated successfully, but these errors were encountered: