Replace Go HTML template rendering with a Bun + TSX build-time static site generator. Go backend becomes API-only for auth. Frontend: - Custom JSX-to-HTML-string factory (zero dependencies) - TSX components for Header, Footer, index page, login page - Client-side login.ts handles tab switching and fetch()-based auth - Bun bundler compiles client JS, build.ts renders pages to dist/ Backend: - Auth handlers return JSON (POST /api/login, POST /api/register) - Login page served as static HTML from dist/ - Static assets served from /assets/ (public) - Auth middleware unchanged (cookie check, redirect to /login) - Removed template parsing and renderPage Dockerfile: - 3-stage build: Bun frontend -> Go backend -> alpine runtime - Frontend dist copied to /app/dist in final image Removed: templates/, static/css/ (replaced by frontend/)
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
import { mkdir, cp, rm } from "fs/promises";
|
|
import { join } from "path";
|
|
import { renderIndex } from "./src/index";
|
|
import { renderLogin } from "./src/login";
|
|
|
|
const DIST = join(import.meta.dir, "dist");
|
|
|
|
async function build() {
|
|
// Clean dist/
|
|
await rm(DIST, { recursive: true, force: true });
|
|
await mkdir(join(DIST, "assets"), { recursive: true });
|
|
|
|
// Bundle client-side JS
|
|
const result = await Bun.build({
|
|
entrypoints: [join(import.meta.dir, "src/client/login.ts")],
|
|
outdir: join(DIST, "assets"),
|
|
naming: "[name].js",
|
|
minify: true,
|
|
});
|
|
|
|
if (!result.success) {
|
|
console.error("JS build failed:");
|
|
for (const log of result.logs) {
|
|
console.error(log);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
|
|
// Copy CSS
|
|
await cp(
|
|
join(import.meta.dir, "src/styles/global.css"),
|
|
join(DIST, "assets/global.css"),
|
|
);
|
|
|
|
// Render HTML pages
|
|
await Bun.write(join(DIST, "index.html"), renderIndex());
|
|
await Bun.write(join(DIST, "login.html"), renderLogin("login.js"));
|
|
|
|
console.log("Build complete \u2192 dist/");
|
|
}
|
|
|
|
build();
|