@@ -2,6 +2,7 @@ const fs = require('fs')
2
2
const path = require ( 'path' )
3
3
4
4
let manifest = null
5
+ const assetsCache = { }
5
6
6
7
// Configuration for manual CSS ordering
7
8
const CSS_ORDER_CONFIG = {
@@ -26,18 +27,22 @@ function readManifest () {
26
27
if ( process . env . NODE_ENV !== 'production' ) {
27
28
return { } // No manifest needed in dev
28
29
}
29
- if ( manifest ) {
30
- return manifest
31
- }
30
+
32
31
try {
33
32
const manifestPath = path . resolve ( __dirname , '../public/build/.vite/manifest.json' )
34
- if ( fs . existsSync ( manifestPath ) ) {
35
- manifest = JSON . parse ( fs . readFileSync ( manifestPath , 'utf-8' ) )
36
- return manifest
37
- } else {
33
+ if ( ! fs . existsSync ( manifestPath ) ) {
38
34
console . error ( 'Vite manifest.json not found! Run `npm run build`.' )
39
35
return { }
40
36
}
37
+
38
+ // Check if manifest has changed
39
+ const currentManifest = JSON . parse ( fs . readFileSync ( manifestPath , 'utf-8' ) )
40
+ if ( ! manifest || JSON . stringify ( manifest ) !== JSON . stringify ( currentManifest ) ) {
41
+ manifest = currentManifest
42
+ // Invalidate cache when manifest changes
43
+ Object . keys ( assetsCache ) . forEach ( key => delete assetsCache [ key ] )
44
+ }
45
+ return manifest
41
46
} catch ( err ) {
42
47
console . error ( 'Error reading Vite manifest.json:' , err )
43
48
return { }
@@ -46,6 +51,11 @@ function readManifest () {
46
51
47
52
// Helper function to get asset paths for an entry point
48
53
function getViteAssets ( entryName ) {
54
+ // Check cache first
55
+ if ( assetsCache [ entryName ] ) {
56
+ return assetsCache [ entryName ] ;
57
+ }
58
+
49
59
const manifestData = readManifest ( ) ;
50
60
const assets = { js : [ ] , css : [ ] } ;
51
61
const isProduction = process . env . NODE_ENV === 'production' ;
@@ -84,6 +94,9 @@ function getViteAssets(entryName) {
84
94
assets . css = orderedCss ;
85
95
}
86
96
97
+ // Cache the result
98
+ assetsCache [ entryName ] = assets ;
99
+
87
100
return assets ;
88
101
}
89
102
0 commit comments