From 6ea4997fcf7cf0ae4c18bce9418817ff00e4727f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 17 Jan 2017 15:58:08 -0600 Subject: [PATCH] Add mix file for loading versioned mix files. --- src/Illuminate/Foundation/helpers.php | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/Illuminate/Foundation/helpers.php b/src/Illuminate/Foundation/helpers.php index fa6fe857d9ee..0a9c70da57f3 100644 --- a/src/Illuminate/Foundation/helpers.php +++ b/src/Illuminate/Foundation/helpers.php @@ -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.