How to use different assets if local or live

When building locally I want to use an unminified version of my JS. On the live site, I want to use the compiled and uglified version.

In my theme, what’s the best way to output the correct one?

Solutions Collecting From Web of "How to use different assets if local or live"

WordPress has constants that can be defined in the wp-config.php. Have a read here

Something like this might help

//setup the production names for the files
$js_file = 'scripts.min.js';
$css_file = 'styles-compressed.css';

//check for WP_DEBUG constant status
if( defined( 'WP_DEBUG' ) && WP_DEBUG ) {

    //check for SCRIPT_DEBUG constant status
    if( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
        $js_file = 'scripts.js';
        $css_file = 'styles-development.css';

//load the files
wp_enqueue_script( 'plugin_scripts', $basepath . '/js/' . $js_file  );
wp_enqueue_style( 'plugin_styles', $basepath . '/css/' . $css_file  );