PHP code example of wpackio / enqueue

1. Go to this page and download the library: Download wpackio/enqueue library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wpackio / enqueue example snippets




// Require the composer autoload for getting conflict-free access to enqueue
'plugin', __FILE__ );



// Require the file yourself
uginEnqueue( 'appName', 'outputPath', '1.0.0', 'plugin', __FILE__ );


// Assuming this is the main plugin file.

// Require the composer autoload for getting conflict-free access to enqueue
 __construct() {
		// It is important that we init the Enqueue class right at the plugin/theme load time
		$this->enqueue = new \WPackio\Enqueue( 'wpackplugin', 'dist', '1.0.0', 'plugin', __FILE__ );
		// Enqueue a few of our entry points
		add_action( 'wp_enqueue_scripts', [ $this, 'plugin_enqueue' ] );
	}


	public function plugin_enqueue() {
		$this->enqueue->enqueue( 'app', 'main', [] );
		$this->enqueue->enqueue( 'app', 'mobile', [] );
		$this->enqueue->enqueue( 'foo', 'main', [] );
	}
}


// Init
new MyPluginInit();

[
	'js' => true,
	'css' => true,
	'js_dep' => [],
	'css_dep' => [],
	'in_footer' => true,
	'media' => 'all',
	'main_js_handle' => null,
	'runtime_js_handle' => null,
];

add_filter( 'wpackio_print_public_path', 'set_public_path_to_cdn' );

function set_public_path_to_cdn( $publichPathUrl ) {
	$home_url = get_home_url(); // WordPress home url
	$cdn_url = 'https://cdn.example.com'; // CDN url

	// replace wordpress home url with cdn url
	return str_replace($home_url, $cdn_url, $publichPathUrl);
}

add_filter( 'wpackio_print_public_path', 'set_public_path_to_cdn', 10, 2 );

function set_public_path_to_cdn( $publichPathUrl, $appName ) {
	
	// check for our plugin
	if( 'myPlugin' !== $appName ) return $publichPathUrl;

	$home_url = get_home_url(); // WordPress home url
	$cdn_url = 'https://cdn.example.com'; // CDN url

	// replace WordPress home url with cdn url
	return str_replace($home_url, $cdn_url, $publichPathUrl);
}