Skip to content

Commit

Permalink
Improve webpack configuration for the development scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Apr 11, 2022
1 parent 4f67b8e commit b1f7065
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/wp-includes/assets/development/react-refresh-entry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array('wp-react-refresh-runtime'), 'version' => '8151afc94a5ebc73b7a8229f0d7ee352');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => '4fb86f241c3b2d9d9e0411b507079823');
12 changes: 9 additions & 3 deletions src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ function wp_get_script_polyfill( $scripts, $tests ) {
* @param WP_Scripts $scripts WP_Scripts object.
*/
function wp_register_development_scripts( $scripts ) {
if ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) {
if (
! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG
|| empty( $scripts->registered['react'] )
) {
return;
}

Expand All @@ -234,7 +237,10 @@ function wp_register_development_scripts( $scripts ) {
);

foreach ( $development_scripts as $script_name ) {
$assets = include ABSPATH . WPINC . "/js/dist/development/$script_name.php";
$assets = include ABSPATH . WPINC . "/assets/development/$script_name.php";
if ( ! is_array( $assets ) ) {
return;
}
$scripts->add(
'wp-' . $script_name,
"/wp-includes/js/dist/development/$script_name.js",
Expand All @@ -244,7 +250,7 @@ function wp_register_development_scripts( $scripts ) {
}

// See https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/docs/TROUBLESHOOTING.md#externalising-react.
$scripts->query( 'react' )->deps[] = 'wp-react-refresh-entry';
$scripts->registered['react']->deps[] = 'wp-react-refresh-entry';
}

/**
Expand Down
5 changes: 4 additions & 1 deletion tools/webpack/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module.exports = function( env = { environment: 'production', buildTarget: false
'react-refresh-entry':
'@pmmmwh/react-refresh-webpack-plugin/client/ReactRefreshEntry.js',
},
plugins: [ new DependencyExtractionWebpackPlugin() ],
plugins: [ new DependencyExtractionWebpackPlugin( {
outputFilename: '../../../assets/development/[name].php',
} ) ],
},
{
...sharedConfig,
Expand All @@ -51,6 +53,7 @@ module.exports = function( env = { environment: 'production', buildTarget: false
plugins: [
new DependencyExtractionWebpackPlugin( {
useDefaults: false,
outputFilename: '../../../assets/development/[name].php'
} ),
],
},
Expand Down

0 comments on commit b1f7065

Please sign in to comment.