Skip to content

Commit

Permalink
Update Changelog and Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Apr 4, 2022
1 parent b8ba979 commit 7380b76
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Mix

## 1.2.0 - 2022-04-04

- Added support for using `mix()` in child themes by using the `is_child` argument or by using `mix_child()`.
- Converted the second parameter in `mix()` to an `$args` array while keeping backwards compatibility with the `$manifest_directory` parameter.

## 1.1.0 – 2019-02-08

- Added `mix_any()` as a new function to work with Mix outside of WordPress themes. Read [the documentation in the README](https://github.com/mindkomm/theme-lib-mix#mix_any).
Expand Down
56 changes: 37 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A [Laravel Mix](https://github.com/JeffreyWay/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:
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:

```json
{
Expand All @@ -11,7 +11,7 @@ The mix function is useful if you want to enable **cache busting** for your them
}
```

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

## Installation

Expand All @@ -23,7 +23,7 @@ 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](https://github.com/JeffreyWay/laravel-mix/blob/master/docs/versioning.md)) in the `build` folder of your theme.
The `mix()` function assumes that you have a `mix-manifest.json` (generated by the [version function of Laravel Mix](https://github.com/JeffreyWay/laravel-mix/blob/master/docs/versioning.md)) in the `build` folder of your theme.

```php
add_action( 'wp_enqueue_scripts', function() {
Expand All @@ -40,40 +40,58 @@ If the mix function can’t find your asset file in the manifest file, it will r

| Name | Return Type | Summary/Returns |
| --- | --- | --- |
| [mix](#mix) | `string` | Gets the path to a versioned Mix file in a theme.<br><br>*Returns:* The versioned file URL. |
| [mix_any](#mix_any) | `string` | Gets the path to a versioned Mix file.<br><br>*Returns:* The versioned file URL. |
| [mix()](#mix) | `string` | Gets the path to a versioned Mix file in a theme.<br><br>*Returns:* The versioned file URL. |
| [mix_child()](#mix_child) | `string` | Gets the path to a versioned Mix file in a **child theme**.<br><br>*Returns:* The versioned file URL. |
| [mix_any()](#mix_any) | `string` | Gets the path to a versioned Mix file outside of your theme folders.<br><br>*Returns:* The versioned file URL. |

### mix
### mix()

Gets the path to a versioned Mix file in a theme.

Use this function if you want to load theme dependencies. This function will cache the contents
of the manifest file for you. This also means that you can’t work with different mix locations.
For that, you’d need to use `mix_any()`.
Use this function if you want to load theme dependencies. This function will cache the contents of the manifest files for you.

Inspired by <https://www.sitepoint.com/use-laravel-mix-non-laravel-projects/>.
- If you want to use mix in a child theme, use `mix_child()`.
- If you want to use mix outside of your theme folder, you can use `mix_any()`.

**since** 1.0.0

`mix( string $path, string $manifest_directory = build )`
`mix( string $path, array $args = [] )`

**Returns:** `string` The versioned file URL.

| Name | Type | Description |
| --- | --- | --- |
| $path | `string` | The relative path to the file. |
| $manifest_directory | `string` | Optional. Custom path to manifest directory. Default 'build'. |
| $args | `array` | Optional. An array of arguments for the function. |

---

### mix\_any

Gets the path to a versioned Mix file.
### mix\_child()

Gets the path to a versioned Mix file in a child theme.

Similar to [`mix()`](#mix), but tries to load a file from the child theme first.

**since** 1.2.0

`mix_child( string $path, array $args = [] )`

```php
add_action( 'wp_enqueue_scripts', function() {
wp_enqueue_style(
'theme-styles-child',
mix_child( 'build/css/styles-child.css' ),
[],
null
);
} );
```

### mix\_any()

Gets the path to a versioned Mix file outside of your theme folders.

The difference to the `mix()` function is that for this function, you need to provide the
absolute paths to the file and the manifest directory. The benefit is that it’s more versatile
and that you can use it for functionality that might not live in a theme, but in a plugin or a
symlinked package.
The difference to the `mix()` function is that for this function, you need to provide the absolute paths to the file and the manifest directory. The benefit is that it’s more versatile and that you can use it for functionality that might not live in a theme, but in a plugin, vendor packages or in a symlinked package.

**since** 1.1.0

Expand Down

0 comments on commit 7380b76

Please sign in to comment.