Giter Site home page Giter Site logo

theme-lib-mix's Introduction

Mix

A Laravel Mix function for WordPress themes.

The mix function is useful if you want to enable cache busting for your theme asset files (CSS, JavaScript, images, icon sprites). Laravel Mix allows you to create a mix-manifest.json file, which might look like this:

{
    "/css/styles.css": "/css/styles.css?id=6ed48b0b831e80bd7549",
    "/js/scripts.js": "/js/scripts.js?id=1bdd07b944e933aa88aa",
}

The ID parameter is a hash of the file contents that changes every time that you make a change to a file. The mix() function provided in this package allows you to use these hashed URLs for enqueueing your assets in your WordPress theme.

Installation

You can install the package via Composer:

composer require mindkomm/theme-lib-mix

Usage

The mix function assumes that you have a mix-manifest.json (generated by the version function of Laravel Mix) in the build folder of your theme.

add_action( 'wp_enqueue_scripts', function() {
    wp_enqueue_style(
        'styles',
        mix( 'build/css/styles.css' )
    );
} );

If the mix function can’t find your asset file in the manifest file, it will return the asset URL through get_theme_file_uri as a fallback.

Functions

Name Summary Type Returns/Description
mix Get the path to a versioned Mix file. string The file URL.

mix

Gets the path to a versioned Mix file.

Inspired by https://www.sitepoint.com/use-laravel-mix-non-laravel-projects/

mix( string $path, string $manifest_directory = build )

Returns: string The file URL.

Name Type Description
$path string The relative path to the file.
$manifest_directory string Optional. Custom path to manifest directory. Default 'build'.

Support

This is a library that we use at MIND to develop WordPress themes. You’re free to use it, but currently, we don’t provide any support.

theme-lib-mix's People

Contributors

gchtr avatar

Watchers

James Cloos avatar sidouglas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.