Created
November 28, 2018 04:19
-
-
Save torounit/bc411028f7942542e003c64ed08bb2d3 to your computer and use it in GitHub Desktop.
WordPress の管理画面で React が圧縮されるとデバッグがしづらいので、圧縮前のヤツを読み込むようにするプラグイン。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Unminify vendor scripts. | |
*/ | |
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | |
add_action( 'admin_print_scripts', function () { | |
global $wp_scripts; | |
unminify_execute( [ | |
'react', | |
'react-dom', | |
], $wp_scripts ); | |
} ); | |
} | |
/** | |
* @param string[] $targets | |
* @param WP_Dependencies $dependencies | |
*/ | |
function unminify_execute( array $targets, WP_Dependencies $dependencies ) { | |
foreach ( $targets as $target ) { | |
if ( ! empty( $dependencies->registered[ $target ] ) ) { | |
unminify_replace_src( $dependencies->registered[ $target ] ); | |
} | |
} | |
} | |
/** | |
* @param _WP_Dependency $dependency | |
*/ | |
function unminify_replace_src( _WP_Dependency $dependency ) { | |
if ( ! empty( $dependency->src ) && is_string( $dependency->src ) ) { | |
$dependency->src = str_replace( '.min', '', $dependency->src ); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment