Skip to content

Commit

Permalink
Add mix file for loading versioned mix files.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 17, 2017
1 parent f578bbc commit 6ea4997
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Illuminate/Foundation/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,45 @@ function method_field($method)
}
}

if (! function_exists('mix')) {
/**
* Get the path to a versioned Mix file.
*
* @param string $path
* @return \Illuminate\Support\HtmlString
*
* @throws \InvalidArgumentException
*/
function mix($path)
{
static $manifest;
static $shouldHotReload;

if (! $manifest) {
if (! file_exists($manifestPath = public_path('mix-manifest.json'))) {
throw new Exception('The Mix manifest does not exist.');
}

$manifest = json_decode(file_get_contents($manifestPath), true);
}

if (! starts_with($path, '/')) {
$path = "/{$path}";
}

if (! array_key_exists($path, $manifest)) {
throw new Exception(
"Unable to locate Mix file: {$path}. Please check your ".
"webpack.mix.js output paths and try again."
);
}

return $shouldHotReload = file_exists(public_path('hot'))
? new HtmlString("http://localhost:8080{$manifest[$path]}")
: new HtmlString(url($manifest[$path]));
}
}

if (! function_exists('old')) {
/**
* Retrieve an old input item.
Expand Down

0 comments on commit 6ea4997

Please sign in to comment.