Personal no-bs blogging platform.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import { readdir, stat, mkdir, rm } from "node:fs/promises";import { join } from "node:path";
const CLIENT_DIR = join(import.meta.dir, "client");const PUBLIC_DIR = join(import.meta.dir, "../public");
/** * Automatically bundles `src/client/<module-name>/...` * into `public/static/<module-name>/... * and becomes available at `/static/<module-name>/index.js` */export async function bundle_typescript() { await rm(PUBLIC_DIR, { force: true, recursive: true }); await mkdir(PUBLIC_DIR, {}); const entries = await readdir(CLIENT_DIR);
for (const module_name of entries) { const module_path = join(CLIENT_DIR, module_name);
const info = await stat(module_path);
if (!info.isDirectory()) continue;
const files = await readdir(module_path);
const entrypoints = files .filter(file => file.endsWith(".ts")) .map(file => join(module_path, file));
if (entrypoints.length === 0) continue;
const result = await Bun.build({ entrypoints,
outdir: join(PUBLIC_DIR, module_name),
target: "browser", format: "esm", splitting: true,
minify: true, sourcemap: "none", env: "disable",
banner: "// Developed by Poyo.",
naming: { entry: "[name].js", chunk: "chunks/[name]-[hash].js", asset: "assets/[name]-[hash].[ext]" } });
if (!result.success) { console.error(result.logs); throw new Error(`Failed to bundle "${module_name}"`); } }}