PHP code example of kanopi / pack-asset-loader
1. Go to this page and download the library: Download kanopi/pack-asset-loader 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/ */
kanopi / pack-asset-loader example snippets
use Kanopi\Assets\Registry\WordPress;
$loader = WordPress(
new LoaderConfiguration(
WordPress::read_theme_version(),
[
// ... list of Domain names, no protocol or path
'domain-name.com',
'staging.domain-name.com'
],
'/assets/dist/webpack-assets.json'
)
);
$loader->register_frontend_scripts( function ( $_registry ) {
$loader = $_registry->asset_loader();
$loader->register_vendor_script( 'central' );
$loader->register_vendor_script( 'vendor' );
$loader->register_runtime_script( 'runtime', [ 'jquery' ] );
$loader->register_style( 'theme' );
$loader->register_script( 'theme-app' );
$loader->enqueue_assets();
// Required theme stylesheet
wp_register_style(
'site-theme',
esc_url_raw( get_stylesheet_directory_uri() . '/style.css' ),
[],
$_registry::read_theme_version();
);
wp_enqueue_style( 'site-theme' );
});
use Kanopi\Assets\Registry\WordPress;
$loader = WordPress(
new LoaderConfiguration(
WordPress::read_theme_version(),
[
// ... list of Domain names, no protocol or path
'domain-name.com',
'staging.domain-name.com'
],
'/assets/dist/webpack-assets.json'
)
);
$loader->register_frontend_scripts( function ( $_registry ) {
$loader = $_registry->asset_loader();
$loader->register_vendor_script( 'central' );
$loader->register_vendor_script( 'vendor' );
$loader->register_runtime_script( 'runtime', [ 'jquery' ] );
$loader->register_style( 'theme' );
$loader->register_style( 'song' );
$loader->register_script( 'theme-app' );
$loader->register_script( 'song-app' );
$loader->enqueue_assets();
// Required theme stylesheet
wp_register_style(
'site-theme',
esc_url_raw( get_stylesheet_directory_uri() . '/style.css' ),
[],
$_registry::read_theme_version();
);
wp_enqueue_style( 'site-theme' );
});
use Kanopi\Assets\Registry\WordPress;
$loader = WordPress(
new LoaderConfiguration(
WordPress::read_theme_version(),
[
// ... list of Domain names, no protocol or path
'domain-name.com',
'staging.domain-name.com'
],
'/assets/dist/webpack-assets.json'
)
);
$loader->register_frontend_scripts( function ( $_registry ) {
$loader = $_registry->asset_loader();
$loader->register_vendor_script( 'central' );
$loader->register_vendor_script( 'vendor' );
$loader->register_runtime_script( 'runtime', [ 'jquery' ] );
$loader->register_style( 'theme' );
$loader->register_style( 'song-listing' );
$loader->register_script( 'theme-app' );
$loader->register_script( 'song-listing-app' );
// Note, the Testimonial script and style are not