-
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
Automate updating the list of dependencies when registering JavaScript scripts with PHP #14837
Comments
Note that question about how to handle PHP side to automated dependency loading in Jetpack: Automattic/jetpack#11591 |
We took the same assumption in Gutenberg, we always include gutenberg/lib/client-assets.php Lines 186 to 192 in 1dcda6f
|
There is this list of default scripts included and registered by WordPress It looks like Gutenberg uses indirectly 4 of them:
It's important to know, as they have to be included in the webpack automation which creates the list of dependencies which has just landed with #14869. |
We'll need to look at each one, but in general I'd like to see these leverage For example, gutenberg/packages/edit-post/src/store/effects.js Lines 41 to 42 in 5430dce
This could become: import postboxes from 'postbox';
// …
if ( postboxes.page !== postType ) {
postboxes.add_postbox_toggles( postType ); The webpack plugin can handle externalizing, adding the script handle to the dependency list, and the process becomes automated. Are these scripts ever expected to be used without being processed by the webpack build? The downside would be that because I do wonder how these "legacy" scripts should be handled going forward
I think it would be best to move ahead implementing custom handlers for Gutenberg to externalize this scripts as needed. If there is demand for making more legacy scripts available, we can figure out how best to address that when the need becomes clear. |
@youknowriad or @aduth - do you have some recommendations on how to handle those legacy dependencies? In general, this is an issue regardless as they are never listed for npm packages. The question is whether we are fine with that and patch it manually on the WordPress side in PHP files as it happens today? Or do we want to mark them as externals in webpack plugin and add some fancy logic to make it work? |
This was discussed in today's Core JS meeting (link requires registration): https://wordpress.slack.com/archives/C5UNMSU4R/p1556028213146100 From the discussion there, it was suggested as a short-term solution to continue referencing the Pseudo-code: wp_enqueue_script(
'my-script',
plugins_url( 'script.js', __FILE__ ),
array_merge(
json_decode( file_get_contents( 'script.deps.json' ) ),
array( 'postbox' )
)
); |
Shared initially on WordPress.org Slack (link requires registration at https://make.wordpress.org/chat/):
https://wordpress.slack.com/archives/C5UNMSU4R/p1554453132137700
All the code can be found in this PR: Automattic/wp-calypso#31513. It's an improved version of how Gutenberg handles external scripts in webpack config which can be found here:
gutenberg/packages/scripts/config/webpack.config.js
Lines 13 to 64 in 244d7ce
The idea is to copy the original webpack plugin to externalize WordPress dependencies and convert it to
@wordpress/*
package and then use it instead of the currently used code. Next step would be to update the way dependencies for packages are discovered. At the moment everything is hardcoded:gutenberg/lib/client-assets.php
Lines 179 to 194 in 1dcda6f
It should be possible to make it fully automated with the webpack plugin discussed.
The text was updated successfully, but these errors were encountered: