Skip to content

Helper class for working with Laravel Mix in WordPress themes and plugins.

License

Notifications You must be signed in to change notification settings

themehybrid/hybrid-mix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hybrid\Mix

Hybrid Mix is a class for working with Lavarel Mix. It adds helper methods for quickly grabbing asset files cached in the mix-manifest.json file.

Requirements

  • WordPress 5.7+.
  • PHP 5.6+ (preferably 7+).
  • Composer for managing PHP dependencies.

Documentation

Create a new instance of the Hybrid\Mix\Mix class, passing in a file path and file URI to your project's public folder.

use Hybrid\Mix\Mix;

$mix = new Mix(
	'public/folder/path',
	'public/folder/uri'
);

Return the cached asset file URI with an appended ID using the asset() method:

// Stylesheet: public/folder/uri/css/style.css?id=xxx
$mix->asset( 'css/style.css' );

// JavaScript: public/folder/uri/js/app.js?id=xxx
$mix->asset( 'js/app.js' );

When using the core WordPress enqueue functions, make sure to set the $ver parameter to null (not false). The id parameter added to the file URL will serve for cache busting.

// Stylesheet.
wp_enqueue_style( $handle, $mix->asset( 'css/style.css' ), $deps, null, $media );

// JavaScript.
wp_enqueue_script( $handle, $mix->asset( 'js/app.js' ), $deps, null, $in_footer );

Copyright and License

This project is licensed under the GNU GPL, version 2 or later.

2021 © Justin Tadlock.

About

Helper class for working with Laravel Mix in WordPress themes and plugins.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages