Skip to content

Commit 86d9e78

Browse files
committed
update viteconfig
1 parent 646d26e commit 86d9e78

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

vite.config.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { defineConfig } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import 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/
88
export 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

Comments
 (0)