11import { defineConfig } from 'vite'
22import react from '@vitejs/plugin-react'
33import tailwindcss from '@tailwindcss/vite'
4- import { copyFileSync } from 'fs'
5- import { join } from 'path'
4+ import * as fs from 'node: fs'
5+ import * as path from 'node: path'
66
77// https://vite.dev/config/
88export default defineConfig ( {
@@ -13,9 +13,20 @@ export default defineConfig({
1313 {
1414 name : 'copy-index-to-404' ,
1515 closeBundle ( ) {
16- const distPath = join ( __dirname , 'dist' )
17- copyFileSync ( join ( distPath , 'index.html' ) , join ( distPath , '404.html' ) )
18- console . log ( '✅ Copied index.html to 404.html for GitHub Pages SPA routing' )
16+ try {
17+ const distPath = path . resolve ( 'dist' )
18+ const indexPath = path . join ( distPath , 'index.html' )
19+ const notFoundPath = path . join ( distPath , '404.html' )
20+
21+ if ( fs . existsSync ( indexPath ) ) {
22+ fs . copyFileSync ( indexPath , notFoundPath )
23+ // eslint-disable-next-line no-console
24+ console . log ( '✅ Copied index.html to 404.html for GitHub Pages SPA routing' )
25+ }
26+ } catch ( error ) {
27+ // eslint-disable-next-line no-console
28+ console . warn ( '⚠️ Failed to copy index.html to 404.html:' , error )
29+ }
1930 }
2031 }
2132 ] ,
0 commit comments