Skip to content

Commit

Permalink
spa static routes
Browse files Browse the repository at this point in the history
  • Loading branch information
actualwitch committed Jan 5, 2025
1 parent 5063100 commit 0eae8eb
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions scripts/build.spa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import project from "../package.json";
import { getHtml } from "../src/entry/_handlers";
import { assignToWindow } from "../src/utils/hydration";
import { Palette } from "../src/style/palette";
import { ROUTES } from "../src/pages/_router";

// why does this work but running it from Bun.build fails? #justbunthings
await $`bun build ./src/entry/client.tsx --outdir ./spa --minify`;
Expand All @@ -15,23 +16,30 @@ await $`bun build ./src/entry/client.tsx --outdir ./spa --minify`;
// }

const baseUrl = process.env.BASE_URL;
const fullUrl = `${baseUrl ?? ""}/`;
const regex = /\/\w*/gm;

const html = getHtml(
fullUrl,
[assignToWindow("REALM", `"SPA"`), baseUrl && assignToWindow("BASE_URL", `"${baseUrl}"`)],
baseUrl,
);
for (const route of ROUTES) {
const path = route.path.match(regex)?.[0]!;

const fullUrl = `${baseUrl ?? ""}${path}`;

const html = getHtml(
fullUrl,
[assignToWindow("REALM", `"SPA"`), baseUrl && assignToWindow("BASE_URL", `"${baseUrl}"`)],
baseUrl,
);
const pathname = path === "/" ? "index" : path.slice(1);

await Bun.write("./spa/index.html", html);
await Bun.write(`./spa/${pathname}.html`, html);
}

const resolutions = [128, 192, 256, 512, 1024];

await Bun.write(
"./spa/manifest.json",
JSON.stringify({
name: project.name,
start_url: fullUrl,
start_url: `${baseUrl ?? ""}/`,
display: "standalone",
description: project.description,
background_color: Palette.white,
Expand All @@ -47,4 +55,4 @@ await Bun.write(

for (const res of resolutions) {
await $`cp ./.github/assets/experiment-${res}.png ./spa`;
}
}

0 comments on commit 0eae8eb

Please sign in to comment.