Build: Enable React Fast Refresh for block development

Brings the same functionality introduced in the Gutenberg plugin with https://github.com/WordPress/gutenberg/pull/28273. In effect, it brings React Fast Refresh support to WordPress core for block development with `@wordpress/scripts`.

Props walbo, antonvlasenko.
See #51750, #55505.
Follow-up [53135].


Built from https://develop.svn.wordpress.org/trunk@53140


git-svn-id: http://core.svn.wordpress.org/trunk@52729 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
gziolo 2022-04-11 16:10:22 +00:00
parent 8b207b7967
commit 29254bd90a
8 changed files with 1403 additions and 1 deletions

View File

@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-react-refresh-runtime'), 'version' => '8151afc94a5ebc73b7a8229f0d7ee352');

View File

@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => '4fb86f241c3b2d9d9e0411b507079823');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -214,6 +214,45 @@ function wp_get_script_polyfill( $scripts, $tests ) {
return $polyfill;
}
/**
* Registers development scripts that integrate with `@wordpress/scripts`.
*
* @see https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts#start
*
* @since 6.0.0
*
* @param WP_Scripts $scripts WP_Scripts object.
*/
function wp_register_development_scripts( $scripts ) {
if (
! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG
|| empty( $scripts->registered['react'] )
) {
return;
}
$development_scripts = array(
'react-refresh-entry',
'react-refresh-runtime',
);
foreach ( $development_scripts as $script_name ) {
$assets = include ABSPATH . WPINC . '/assets/script-loader-' . $script_name . '.php';
if ( ! is_array( $assets ) ) {
return;
}
$scripts->add(
'wp-' . $script_name,
'/wp-includes/js/dist/development/' . $script_name . '.js',
$assets['dependencies'],
$assets['version']
);
}
// See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react.
$scripts->registered['react']->deps[] = 'wp-react-refresh-entry';
}
/**
* Registers all the WordPress packages scripts that are in the standardized
* `js/dist/` location.
@ -560,6 +599,7 @@ function wp_tinymce_inline_scripts() {
*/
function wp_default_packages( $scripts ) {
wp_default_packages_vendor( $scripts );
wp_register_development_scripts( $scripts );
wp_register_tinymce_scripts( $scripts );
wp_default_packages_scripts( $scripts );

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-53139';
$wp_version = '6.0-alpha-53140';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.