mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-29 00:30:05 +02:00
Re-enabled mix-manifest.json for hashing assets
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\ViewFunctions;
|
||||
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
|
||||
class Asset extends ViewFunction
|
||||
{
|
||||
/** @const Constant description */
|
||||
@@ -19,6 +21,30 @@ class Asset extends ViewFunction
|
||||
*/
|
||||
public function __invoke(string $path): string
|
||||
{
|
||||
$path = '/' . ltrim($path, '/');
|
||||
|
||||
if ($this->mixManifest()->has($path)) {
|
||||
$path = $this->mixManifest()->get($path);
|
||||
}
|
||||
|
||||
return self::ASSET_PATH . ltrim($path, '/');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the mix manifest collection.
|
||||
*
|
||||
* @return \Tightenco\Collect\Support\Collection
|
||||
*/
|
||||
protected function mixManifest(): Collection
|
||||
{
|
||||
$mixManifest = $this->container->get('base_path') . '/' . self::ASSET_PATH . 'mix-manifest.json';
|
||||
|
||||
if (! is_file($mixManifest)) {
|
||||
return new Collection();
|
||||
}
|
||||
|
||||
return Collection::make(
|
||||
json_decode(file_get_contents($mixManifest), true) ?? []
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -9,10 +9,12 @@ class AssetTest extends TestCase
|
||||
{
|
||||
public function test_it_can_return_an_asset_path(): void
|
||||
{
|
||||
$this->container->set('base_path', $this->filePath('.'));
|
||||
$asset = new Asset($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('app/assets/css/app.css', $asset('css/app.css'));
|
||||
$this->assertEquals('app/assets/js/app.js', $asset('js/app.js'));
|
||||
$this->assertEquals('app/assets/app.css?id=417c7a9bc03852aafb27', $asset('app.css'));
|
||||
$this->assertEquals('app/assets/app.js?id=6753a7269276c7b52692', $asset('app.js'));
|
||||
$this->assertEquals('app/assets/images/icon.png', $asset('images/icon.png'));
|
||||
}
|
||||
|
||||
public function test_it_can_return_an_asset_with_a_subdirectory(): void
|
||||
@@ -21,7 +23,8 @@ class AssetTest extends TestCase
|
||||
|
||||
$asset = new Asset($this->container, $this->config);
|
||||
|
||||
$this->assertEquals('app/assets/css/app.css', $asset('css/app.css'));
|
||||
$this->assertEquals('app/assets/js/app.js', $asset('js/app.js'));
|
||||
$this->assertEquals('app/assets/app.css?id=417c7a9bc03852aafb27', $asset('app.css'));
|
||||
$this->assertEquals('app/assets/app.js?id=6753a7269276c7b52692', $asset('app.js'));
|
||||
$this->assertEquals('app/assets/images/icon.png', $asset('images/icon.png'));
|
||||
}
|
||||
}
|
||||
|
4
tests/_files/app/assets/mix-manifest.json
Normal file
4
tests/_files/app/assets/mix-manifest.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"/app.css": "/app.css?id=417c7a9bc03852aafb27",
|
||||
"/app.js": "/app.js?id=6753a7269276c7b52692"
|
||||
}
|
@@ -2,7 +2,7 @@ let mix = require('laravel-mix');
|
||||
let tailwindcss = require('tailwindcss');
|
||||
require('laravel-mix-purgecss');
|
||||
|
||||
mix.setPublicPath('.');
|
||||
mix.setPublicPath('app/assets');
|
||||
|
||||
mix.webpackConfig({
|
||||
watchOptions: { ignored: ['node_modules', 'app/vendor'] }
|
||||
|
Reference in New Issue
Block a user