PHP code example of milbareu / wordpress-webpack-asset-manager

1. Go to this page and download the library: Download milbareu/wordpress-webpack-asset-manager 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/ */

    

milbareu / wordpress-webpack-asset-manager example snippets


// Example: Enqueue the 'main' bundle with the namespace 'mytheme'
WPAssets::enqueueBundle('main', 'mytheme');

// Example: Enqueue the 'editor' bundle with the default namespace
WPAssets::enqueueBundle('editor');



use MB\WPAssets\WPAssets;

// Register the theme assets
add_action('wp_enqueue_scripts', function () {
    WPAssets::enqueueBundle('main', 'mytheme');
}, 100);

// Register assets for the block editor
add_action('enqueue_block_editor_assets', function () {
    WPAssets::enqueueBundle('editor');
}, 100);

WPAssets::enqueueBundle('main', 'mytheme');

$mainCssUrl = WPAssets::getAsset('main.css'); // Get URL of main.css

$deps = WPAssets::getAssetDependencies('main.js');
json
{
  "entrypoints": {
    "main": {
      "assets": {
        "css": [
          "/styles/main.css"
        ],
        "js": [
          "/scripts/main.js"
        ],
        "php": [
          "/scripts/main.asset.php"
        ]
      }
    },
    "editor": {
      "assets": {
        "css": [
          "/styles/editor.css"
        ],
        "js": [
          "/scripts/editor.js"
        ],
        "php": [
          "/scripts/editor.asset.php"
        ]
      }
    }
  }
}
json
"php": [
"/scripts/main.asset.php"
]