@@ -28,53 +28,59 @@ function readManifest () {
2828}
2929
3030// Helper function to get asset paths for an entry point
31- function getViteAssets ( entryName ) {
32- const manifestData = readManifest ( )
33- const assets = { js : [ ] , css : [ ] }
34- const isProduction = process . env . NODE_ENV === 'production'
31+ function getViteAssets ( entryName ) {
32+ const manifestData = readManifest ( ) ;
33+ const assets = { js : [ ] , css : [ ] } ;
34+ const isProduction = process . env . NODE_ENV === 'production' ;
3535
3636 if ( isProduction ) {
37- const entryKey = `public/js/${ entryName } .js` // Assuming entry points are in public/js
38- const entryChunk = manifestData [ entryKey ]
37+ const entryKey = `public/js/${ entryName } .js` ;
38+ const entryChunk = manifestData [ entryKey ] ;
3939
4040 if ( entryChunk ) {
41- // Add the main entry JS file
42- if ( entryChunk . file ) {
43- assets . js . push ( `/build/${ entryChunk . file } ` )
44- }
45- // Add CSS files associated with the entry
46- if ( entryChunk . css ) {
47- entryChunk . css . forEach ( cssFile => assets . css . push ( `/build/${ cssFile } ` ) )
48- }
49- // Add JS imports (dynamic imports, vendor chunks) - might need refinement based on actual manifest structure
50- if ( entryChunk . imports ) {
51- entryChunk . imports . forEach ( importKey => {
52- const importChunk = manifestData [ importKey ]
53- if ( importChunk && importChunk . file && importChunk . file . endsWith ( '.js' ) ) {
54- assets . js . push ( `/build/${ importChunk . file } ` )
55- }
56- // Also check for CSS associated with imported chunks
57- if ( importChunk && importChunk . css ) {
58- importChunk . css . forEach ( cssFile => {
59- // Avoid duplicates
60- if ( ! assets . css . includes ( `/build/${ cssFile } ` ) ) {
61- assets . css . push ( `/build/${ cssFile } ` )
62- }
63- } )
64- }
65- } )
66- }
41+ processChunk ( entryChunk , manifestData , assets ) ;
6742 } else {
68- console . warn ( `Vite manifest entry not found for: ${ entryKey } ` )
43+ console . warn ( `Vite manifest entry not found for: ${ entryKey } ` ) ;
6944 }
7045 } else {
71- // In development, Vite now uses a custom base path
72- assets . js . push ( `/.vite/@vite/client` ) // Vite HMR client with custom base
73- // Request the actual file path relative to the project root with the custom base
74- assets . js . push ( `/.vite/public/js/${ entryName } .js` )
46+ assets . js . push ( `/.vite/@vite/client` ) ;
47+ assets . js . push ( `/.vite/public/js/${ entryName } .js` ) ;
7548 }
7649
77- return assets
50+ return assets ;
51+ }
52+
53+ function processChunk ( chunk , manifestData , assets ) {
54+ if ( chunk . file && ! assets . js . includes ( `/build/${ chunk . file } ` ) ) {
55+ assets . js . push ( `/build/${ chunk . file } ` ) ;
56+ }
57+ if ( chunk . css ) {
58+ chunk . css . forEach ( cssFile => {
59+ if ( ! assets . css . includes ( `/build/${ cssFile } ` ) ) {
60+ assets . css . push ( `/build/${ cssFile } ` ) ;
61+ }
62+ } ) ;
63+ }
64+ if ( chunk . imports ) {
65+ chunk . imports . forEach ( importKey => {
66+ const importChunk = manifestData [ importKey ] ;
67+ if ( importChunk ) {
68+ if ( importChunk . file && importChunk . file . endsWith ( '.js' ) ) {
69+ if ( ! assets . js . includes ( `/build/${ importChunk . file } ` ) ) {
70+ assets . js . push ( `/build/${ importChunk . file } ` ) ;
71+ }
72+ }
73+ if ( importChunk . css ) {
74+ importChunk . css . forEach ( cssFile => {
75+ if ( ! assets . css . includes ( `/build/${ cssFile } ` ) ) {
76+ assets . css . push ( `/build/${ cssFile } ` ) ;
77+ }
78+ } ) ;
79+ }
80+ processChunk ( importChunk , manifestData , assets ) ;
81+ }
82+ } ) ;
83+ }
7884}
7985
8086// Helper to generate HTML tags
0 commit comments