@@ -414,44 +414,58 @@ public function moduleViteAssets( string $fileName, $moduleId ): string
414414 );
415415 }
416416
417- $ manifestPath = rtrim ( $ module [ ' path ' ], DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . ' Public ' . DIRECTORY_SEPARATOR . ' build ' . DIRECTORY_SEPARATOR . ' manifest.json ' ;
417+ $ ds = DIRECTORY_SEPARATOR ;
418418
419- if ( ! file_exists ( $ manifestPath ) ) {
420- throw new NotFoundException (
421- sprintf (
422- __ ( 'The manifest.json can \'t be located inside the module %s on the path: %s ' ),
423- $ module [ 'name ' ],
424- $ manifestPath
425- )
426- );
427- }
419+ $ possiblePaths = [
420+ rtrim ( $ module ['path ' ], $ ds ) . $ ds . 'Public ' . $ ds . 'build ' . $ ds . '.vite ' . $ ds . 'manifest.json ' ,
421+ rtrim ( $ module ['path ' ], $ ds ) . $ ds . 'Public ' . $ ds . 'build ' . $ ds . 'manifest.json '
422+ ];
423+
424+ $ assets = collect ( [] );
425+ $ errors = [];
426+
427+ foreach ( $ possiblePaths as $ manifestPath ) {
428+ if ( ! file_exists ( $ manifestPath ) ) {
429+ $ errors [] = $ manifestPath ;
430+ continue ;
431+ }
432+
433+ $ manifestArray = json_decode ( file_get_contents ( $ manifestPath ), true );
434+
435+ if ( ! isset ( $ manifestArray [ $ fileName ] ) ) {
436+ throw new NotFoundException (
437+ sprintf (
438+ __ ( 'the requested file "%s" can \'t be located inside the manifest.json for the module %s. ' ),
439+ $ fileName ,
440+ $ module [ 'name ' ]
441+ )
442+ );
443+ }
444+
445+ /**
446+ * checks if a css file is declared as well
447+ */
448+ $ jsUrl = asset ( 'modules/ ' . strtolower ( $ moduleId ) . '/build/ ' . $ manifestArray [ $ fileName ][ 'file ' ] ) ?? null ;
428449
429- $ manifestArray = json_decode ( file_get_contents ( $ manifestPath ), true );
450+ if ( ! empty ( $ manifestArray [ $ fileName ][ 'css ' ] ) ) {
451+ $ assets = collect ( $ manifestArray [ $ fileName ][ 'css ' ] )->map ( function ( $ url ) use ( $ moduleId ) {
452+ return '<link rel="stylesheet" href=" ' . asset ( 'modules/ ' . strtolower ( $ moduleId ) . '/build/ ' . $ url ) . '"/> ' ;
453+ } );
454+ }
455+
456+ $ assets ->prepend ( '<script type="module" src=" ' . $ jsUrl . '"></script> ' );
457+ }
430458
431- if ( ! isset ( $ manifestArray [ $ fileName ] ) ) {
459+ if ( count ( $ errors ) === count ( $ possiblePaths ) ) {
432460 throw new NotFoundException (
433461 sprintf (
434- __ ( 'the requested file "%s" can \'t be located inside the manifest.json for the module %s. ' ),
435- $ fileName ,
436- $ module [ ' name ' ]
462+ __ ( 'The manifest file for the module %s wasn \'t found on all possible directories: %s. ' ),
463+ $ module [ ' name ' ] ,
464+ collect ( $ errors )-> join ( ' , ' ),
437465 )
438466 );
439467 }
440468
441- /**
442- * checks if a css file is declared as well
443- */
444- $ jsUrl = asset ( 'modules/ ' . strtolower ( $ moduleId ) . '/build/ ' . $ manifestArray [ $ fileName ][ 'file ' ] ) ?? null ;
445- $ assets = collect ( [] );
446-
447- if ( ! empty ( $ manifestArray [ $ fileName ][ 'css ' ] ) ) {
448- $ assets = collect ( $ manifestArray [ $ fileName ][ 'css ' ] )->map ( function ( $ url ) use ( $ moduleId ) {
449- return '<link rel="stylesheet" href=" ' . asset ( 'modules/ ' . strtolower ( $ moduleId ) . '/build/ ' . $ url ) . '"/> ' ;
450- } );
451- }
452-
453- $ assets ->prepend ( '<script type="module" src=" ' . $ jsUrl . '"></script> ' );
454-
455- return $ assets ->join ( '' );
469+ return $ assets ->flatten ()->join ( '' );
456470 }
457471}
0 commit comments