PHPackages                             milbareu/wordpress-webpack-asset-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. milbareu/wordpress-webpack-asset-manager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

milbareu/wordpress-webpack-asset-manager
========================================

A WordPress asset manager for handling Webpack's manifest.json and enqueuing assets with dependencies.

1.0.8(3mo ago)0488MITPHPPHP &gt;=7.2

Since Sep 17Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/milbareu/wordpress-webpack-asset-manager)[ Packagist](https://packagist.org/packages/milbareu/wordpress-webpack-asset-manager)[ RSS](/packages/milbareu-wordpress-webpack-asset-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)DependenciesVersions (9)Used By (0)

WPAssets - WordPress Asset Manager
==================================

[](#wpassets---wordpress-asset-manager)

Introduction
------------

[](#introduction)

WPAssets is a PHP class designed to manage assets in WordPress. It integrates with Webpack's manifest.json files, automatically enqueuing CSS, JS, and handling PHP dependencies ( with [Dependency Extraction Webpack Plugin](https://www.npmjs.com/package/@wordpress/dependency-extraction-webpack-plugin)) in a structured and scalable way. This streamlines asset management in WordPress themes and plugins.

Features
--------

[](#features)

- Automatic Asset Enqueuing: Easily enqueue JavaScript, CSS, and PHP files defined in Webpack's manifest.json.
- Bundle-Based Asset Management: Manage your assets by bundling them into logical entry points.
- Namespace Support: Add a custom namespace prefix to your assets for better organization.
- PHP Dependency Support: Automatically includes PHP files as part of the asset dependencies.

Install via Composer
--------------------

[](#install-via-composer)

You can install WPAssets via Composer. Run the following command in your WordPress, theme or plugin directory:

```
composer require milbareu/wordpress-webpack-asset-manager
```

1. Enqueueing Assets in WordPress
---------------------------------

[](#1-enqueueing-assets-in-wordpress)

To enqueue a bundle (which includes CSS, JS, and optionally PHP files), use the WPAssets::enqueueBundle() function. This function pulls the required assets from the Webpack-generated manifest.json file.

```
// 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');
```

2. Example Setup in functions.php
---------------------------------

[](#2-example-setup-in-functionsphp)

Here’s an example of how to use WPAssets in a WordPress theme to manage assets:

```
