Asset loading with gulp.js or Grunt

I’ve been messing around with it some more and the best way I can think of is to register the scripts that are going to be combined and set their source to false to prevent other plugins from loading them. I know it’s not the best solution and is a little hacky but can’t think of any other ways. Plus this will only work if the handle name is exactly the same.

function enqueue_scripts() {
    // These files are concatenated into plugins.min.js
    wp_register_script( 'fancybox', false );
    wp_register_script( 'flexslider', false );

    // Concatenated js files
    wp_register_script( 'custom-plugins', get_template_directory_uri() . '/assets/js/build/plugins.min.js', array( 'jquery' ), '1.0', true );

    wp_enqueue_script( 'custom-plugins' );
}

add_action( 'wp_enqueue_scripts', 'enqueue_scripts', 1 );

I also had to add a higher priority on the wp_enqueue_scripts action to make sure that it would take precedence over other plugins.