Skip to content

Commit 9574b6a

Browse files
author
James Wigger
committed
Initial commit
0 parents  commit 9574b6a

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
.DS_Store

composer.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "rootstudio/base-mix-helper",
3+
"description": "Mix standalone function for versioning assets outside of Laravel",
4+
"type": "library",
5+
"license": "none",
6+
"authors": [
7+
{
8+
"name": "James Wigger",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.4.0"
14+
},
15+
"autoload": {
16+
"files": ["mix.php"]
17+
}
18+
}

mix.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Return path to document root
5+
*
6+
* @param string $path
7+
*
8+
* @return string
9+
*/
10+
if (!function_exists('public_path')) {
11+
function public_path($path = '')
12+
{
13+
return $_SERVER['DOCUMENT_ROOT'] . ($path ? '/' . trim($path, '/') : $path);
14+
}
15+
}
16+
17+
/**
18+
* Parse manifest and output versioned asset path
19+
*
20+
* @param string $path
21+
* @param string $manifestDirectory
22+
*
23+
* @return string
24+
* @throws Exception
25+
*/
26+
if (!function_exists('mix')) {
27+
function mix($path, $manifestDirectory = '')
28+
{
29+
static $manifest;
30+
31+
$path = '/' . ltrim($path, '/');
32+
33+
if ($manifestDirectory) {
34+
$manifestDirectory = '/' . ltrim($manifestDirectory, '/');
35+
}
36+
37+
if (!$manifest) {
38+
if (!file_exists($manifestPath = public_path($manifestDirectory . '/mix-manifest.json'))) {
39+
throw new Exception('The Mix manifest does not exist.');
40+
}
41+
42+
$manifest = json_decode(file_get_contents($manifestPath), true);
43+
}
44+
45+
if (!array_key_exists($path, $manifest)) {
46+
throw new Exception(
47+
"Unable to locate Mix file: {$path}. Please check your " .
48+
'webpack.mix.js output paths and try again.'
49+
);
50+
}
51+
52+
if (file_exists(public_path($manifestDirectory . '/hot'))) {
53+
return "http://localhost:8080{$manifest[$path]}";
54+
}
55+
56+
return $manifestDirectory . $manifest[$path];
57+
}
58+
}

0 commit comments

Comments
 (0)