antiseptikk/wordpress-encore

API to enqueue assets generated by @webpack/encore into your WordPress theme.

v1.1.1 2023-09-07 10:57 UTC

This package is auto-updated.

Last update: 2024-12-07 14:01:58 UTC


README

Packagist

Simple and light script to handle and register Webpack Encore assets to WordPress.

Installation

Using Composer

composer require antiseptikk/wordpress-encore

Then in your functions.php file of your theme, load composer auto-loader.

<?php

require_once __DIR__ . '/vendor/autoload.php';

$encore = new \Antiseptikk\Encore('build', '1.0.0', 'my-website.com');

Using WPress composer-skeleton

We recommend using WPress composer-skeleton for using this library, you can use config constants like WP_HOME

<?php

$encore = new \Antiseptikk\Encore('build', '1.0.0', WP_HOME);

Example

<?php

use Antiseptikk\Encore;

class Bootstrap
{
    private $encore;   

    public function __constuct()
    {
        $this->encore = new Encore('build', '1.0.0', WP_HOME);
        add_action('wp_enqueue_scripts', [$this, 'enqueue_assets']);
    }

    public function enqueue_assets()
    {
        $this->encore->enqueue('app', 'main', []);
    }
}

Contribution

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT