diff --git a/package.json b/package.json index ce14050..edfd821 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc -b && vite build", + "build": "tsc -b && vite build && node scripts/postbuild.mjs", "lint": "eslint .", "preview": "vite preview" }, diff --git a/scripts/postbuild.mjs b/scripts/postbuild.mjs new file mode 100644 index 0000000..bba81ba --- /dev/null +++ b/scripts/postbuild.mjs @@ -0,0 +1,12 @@ +import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import { dirname, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), ".."); +const indexHtml = readFileSync(resolve(root, "dist", "index.html"), "utf8"); + +const moreDir = resolve(root, "dist", "more"); +mkdirSync(moreDir, { recursive: true }); +writeFileSync(resolve(moreDir, "index.html"), indexHtml); + +console.log("Copied dist/index.html -> dist/more/index.html"); diff --git a/src/App.tsx b/src/App.tsx index bbcf223..071fa1c 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,7 +7,7 @@ import MorePage from "./pages/MorePage"; export default function App() { const { pathname } = window.location; - if (pathname === "/more" || pathname === "/more/") { + if (/^\/more(\/index\.html)?\/?$/.test(pathname)) { return ; }