File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed
Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 11import tailwindcss from "@tailwindcss/vite" ;
22import react from "@vitejs/plugin-react-swc" ;
3+ import fs from "fs" ;
34import path from "path" ;
4- import { defineConfig } from "vite" ;
5+ import { type Plugin , defineConfig } from "vite" ;
56import sitemap from "vite-plugin-sitemap" ;
67
78// https://vite.dev/config/
89export default defineConfig ( {
910 plugins : [
1011 react ( ) ,
1112 tailwindcss ( ) ,
13+ copyIndexTo404 ( ) ,
1214 sitemap ( {
1315 hostname : "https://libresplit.org" ,
1416 dynamicRoutes : [ "/converter" ] ,
@@ -25,3 +27,23 @@ export default defineConfig({
2527 } ,
2628 } ,
2729} ) ;
30+
31+ // Home spun plugin for copying index.html to 404.html at build time.
32+ // This makes SPA routing work on GitHub pages.
33+ function copyIndexTo404 ( ) : Plugin {
34+ return {
35+ name : "copy-index-to-404" ,
36+ closeBundle ( ) {
37+ const distDir = path . resolve ( __dirname , "dist" ) ;
38+ const indexPath = path . join ( distDir , "index.html" ) ;
39+ const notFoundPath = path . join ( distDir , "404.html" ) ;
40+
41+ if ( fs . existsSync ( indexPath ) ) {
42+ fs . copyFileSync ( indexPath , notFoundPath ) ;
43+ console . log ( "Copied index.html → 404.html for SPA fallback" ) ;
44+ } else {
45+ console . warn ( "⚠️ index.html not found in dist directory" ) ;
46+ }
47+ } ,
48+ } ;
49+ }
You can’t perform that action at this time.
0 commit comments