@@ -7,7 +7,10 @@ const __dirname = path.dirname(__filename);
77
88const projectRoot = path . resolve ( __dirname , '..' ) ;
99const manifestPath = path . resolve ( projectRoot , 'public/dist/.vite/manifest.json' ) ;
10- const htmlPath = path . resolve ( projectRoot , 'public/index.html' ) ;
10+ const htmlPaths = [
11+ path . resolve ( projectRoot , 'public/index.html' ) ,
12+ path . resolve ( projectRoot , 'public/privacy.html' )
13+ ] ;
1114
1215try {
1316 // 1. Read manifest.json
@@ -18,10 +21,15 @@ try {
1821
1922 const manifest = JSON . parse ( fs . readFileSync ( manifestPath , 'utf-8' ) ) ;
2023
21- let html = fs . readFileSync ( htmlPath , 'utf-8' ) ;
22-
23- // Iterate over manifest keys to find entry points and inject their new names
24- Object . keys ( manifest ) . forEach ( key => {
24+ htmlPaths . forEach ( htmlPath => {
25+ if ( ! fs . existsSync ( htmlPath ) ) {
26+ return ;
27+ }
28+
29+ let html = fs . readFileSync ( htmlPath , 'utf-8' ) ;
30+
31+ // Iterate over manifest keys to find entry points and inject their new names
32+ Object . keys ( manifest ) . forEach ( key => {
2533 const entryData = manifest [ key ] ;
2634 if ( entryData && ( entryData . isEntry || entryData . isDynamicEntry ) && entryData . file ) {
2735 // chunk name could be 'main.js' or 'frontend/main.js'
@@ -41,11 +49,12 @@ try {
4149 html = html . replace ( cssRegex , `<link rel="stylesheet" href="/dist/${ cssFile } " id="vite-css">` ) ;
4250 }
4351 }
52+ } ) ;
53+
54+ fs . writeFileSync ( htmlPath , html , 'utf-8' ) ;
55+ console . log ( `[Hash Injector] Successfully updated ${ path . relative ( projectRoot , htmlPath ) } ` ) ;
4456 } ) ;
4557
46- fs . writeFileSync ( htmlPath , html , 'utf-8' ) ;
47- console . log ( `[Hash Injector] Successfully updated public/index.html` ) ;
48-
4958} catch ( error ) {
5059 console . error ( '[Hash Injector] Error:' , error ) ;
5160 process . exit ( 1 ) ;
0 commit comments