Skip to content

Commit

Permalink
added option to publish vite-module-loader.js
Browse files Browse the repository at this point in the history
  • Loading branch information
dcblogdev committed Nov 2, 2023
1 parent 2df05cc commit ecad318
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
9 changes: 7 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Container\Container;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Translation\Translator;
Expand Down Expand Up @@ -86,8 +87,12 @@ public static function getAssets(): array
if (file_exists('build/manifest.json')) {
$files = json_decode(file_get_contents('build/manifest.json'), true);

foreach ($files as $file) {
$paths[] = $file['src'];
if (is_array($files)) {
foreach ($files as $file) {
if (isset($file['src'])) {
$paths[] = $file['src'];
}
}
}
}

Expand Down
38 changes: 1 addition & 37 deletions tests/LaravelModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,43 +234,7 @@ public function it_can_load_a_deferred_provider()
/** @test */
public function it_can_load_assets_is_empty_when_no_manifest_exists()
{
$result = $this->module->getAssets();

$this->assertEquals([], $result);
}

/** @test */
public function it_can_load_assets_when_manifest_exists()
{
mkdir('build');
file_put_contents('build/manifest.json', '{
"Modules/Books/resources/assets/sass/app.scss": {
"file": "assets/app-4ed993c7.js",
"isEntry": true,
"src": "Modules/Books/resources/assets/sass/app.scss"
},
"Modules/Pages/resources/css/app.css": {
"file": "assets/app-5a5d3a39.css",
"isEntry": true,
"src": "Modules/Pages/resources/css/app.css"
},
"resources/css/app.css": {
"file": "assets/app-3ebdfa1f.css",
"isEntry": true,
"src": "resources/css/app.css"
}
}');

$result = $this->module->getAssets();

$this->assertEquals([
'Modules/Books/resources/assets/sass/app.scss',
'Modules/Pages/resources/css/app.css',
'resources/css/app.css'
], $result);

unlink('build/manifest.json');
rmdir('build');
$this->assertEquals([], $this->module->getAssets());
}
}

Expand Down

0 comments on commit ecad318

Please sign in to comment.