PHP code example of atomicsmash / compiler-helpers
1. Go to this page and download the library: Download atomicsmash/compiler-helpers 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/ */
atomicsmash / compiler-helpers example snippets
class Assets extends \AtomicSmash\CompilerHelpers\Assets {
/**
* Constructor
*/
public function __construct() {
$this->context_folder = realpath( __DIR__ . '/../' ); // Required.
$this->build_folder = '/build/'; // Optional. Defaults to `/dist/`.
parent::__construct();
}
}
function scripts() {
$assets = new Assets();
// Styles
$example_stylesheet = $assets->get_cached_asset( 'styles/styles.scss' );
if ( $example_stylesheet === null ) {
throw new Error( "Failed to load stylesheet styles/styles.scss" );
}
wp_enqueue_style( 'handle', $example_stylesheet['source'], $example_stylesheet['dependencies'], $example_stylesheet['version'] );
// Scripts
$example_script = $assets->get_cached_asset( 'scripts/example.ts' );
if ( $example_script === null ) {
throw new Error( "Failed to load script scripts/example.ts" );
}
wp_enqueue_script( 'handle', $example_script['source'], $example_script['dependencies'], $example_script['version'], array( 'strategy' => 'defer' ) );
}
add_action( 'wp_enqueue_scripts', 'scripts', 10 );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.