Skip to content

Commit

Permalink
Extract the JSX Runtime into its own script
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed May 15, 2024
1 parent 1b8dc96 commit afcdcd8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,14 @@ function gutenberg_register_vendor_scripts( $scripts ) {
array( 'react' ),
'18'
);

gutenberg_override_script(
$scripts,
'react-jsx-runtime',
gutenberg_url( 'build/react-jsx-runtime/index.min.js' ),
array(),
'18'
);
}
add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' );

Expand Down
6 changes: 6 additions & 0 deletions packages/dependency-extraction-webpack-plugin/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ function defaultRequestToExternal( request ) {

case 'react-dom':
return 'ReactDOM';

case 'react/jsx-runtime':
return 'ReactJSXRuntime';
}

if ( request.includes( 'react-refresh/runtime' ) ) {
Expand Down Expand Up @@ -117,6 +120,9 @@ function defaultRequestToHandle( request ) {

case 'lodash-es':
return 'lodash';

case 'react/jsx-runtime':
return 'react-jsx-runtime';
}

if ( request.includes( 'react-refresh/runtime' ) ) {
Expand Down
18 changes: 18 additions & 0 deletions tools/webpack/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,22 @@ module.exports = [
} ),
],
},
{
...sharedConfig,
name: 'react-jsx-runtime',
entry: {
'react-jsx-runtime': {
import: 'react/jsx-runtime',
library: {
name: 'ReactJSXRuntime',
type: 'window',
},
},
},
plugins: [
new DependencyExtractionWebpackPlugin( {
useDefaults: false,
} ),
],
},
];

0 comments on commit afcdcd8

Please sign in to comment.