Last active
March 8, 2017 14:00
-
-
Save LasseRafn/705501bf676edb54310d8a5088616b53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (! function_exists('mix')) { | |
/** | |
* Get the path to a versioned Mix file. | |
* | |
* @param string $path | |
* @param string $manifestDirectory | |
* @return \Illuminate\Support\HtmlString | |
* | |
* @throws \Exception | |
*/ | |
function mix($path, $manifestDirectory = '') | |
{ | |
static $manifest; | |
$publicPath = $_SERVER['DOCUMENT_ROOT']; | |
if ($manifestDirectory && ! starts_with($manifestDirectory, '/')) { | |
$manifestDirectory = "/{$manifestDirectory}"; | |
} | |
if (! $manifest) { | |
if (! file_exists($manifestPath = ($manifestDirectory.'/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 file_exists($publicPath . ($manifestDirectory.'/hot')) | |
? new Illuminate\Support\HtmlString("http://localhost:8080{$manifest[$path]}") | |
: new Illuminate\Support\HtmlString($manifestDirectory.$manifest[$path]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment