Skip to content

Instantly share code, notes, and snippets.

@roborourke
Last active May 17, 2020 13:50
Show Gist options
  • Save roborourke/887ccc6a8070cb7dbd69b897bee6af7f to your computer and use it in GitHub Desktop.
Save roborourke/887ccc6a8070cb7dbd69b897bee6af7f to your computer and use it in GitHub Desktop.
Get the development version of react in WordPress without needing a dev version of WP
<?php
/**
* Enable dev mode vendor packages.
*/
if ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) {
return;
}
add_action( 'init', function () {
$scripts = wp_scripts();
$vendor_scripts = array(
'react' => array( 'wp-polyfill' ),
'react-dom' => array( 'react' ),
'moment',
'lodash',
'wp-polyfill-fetch',
'wp-polyfill-formdata',
'wp-polyfill-node-contains',
'wp-polyfill-element-closest',
'wp-polyfill',
);
$vendor_scripts_versions = array(
'react' => '16.6.3',
'react-dom' => '16.6.3',
'moment' => '2.22.2',
'lodash' => '4.17.11',
'wp-polyfill-fetch' => '3.0.0',
'wp-polyfill-formdata' => '3.0.12',
'wp-polyfill-node-contains' => '3.26.0-0',
'wp-polyfill-element-closest' => '2.0.2',
'wp-polyfill' => '7.0.0',
);
foreach ( $vendor_scripts as $handle => $dependencies ) {
if ( is_string( $dependencies ) ) {
$handle = $dependencies;
$dependencies = array();
}
$path = "/wp-includes/js/dist/vendor/$handle.js";
$version = $vendor_scripts_versions[ $handle ];
$scripts->remove( $handle );
$scripts->add( $handle, $path, $dependencies, $version, 1 );
}
return;
}, 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment