crumbun
v0.3.6
Published
Tiny Bun fullstack engine with file routes, Pug templates, and static export.
Maintainers
Readme
crumbun
Tiny Bun fullstack engine with file routes, Pug views, and static export.
Fastest Start
bunx create-crumbun@latest my-appInstall
bun add crumbunSmallest App
import { fileURLToPath } from "node:url";
import { serve } from "crumbun";
const server = await serve({
root: fileURLToPath(new URL("..", import.meta.url)),
});
console.log(`Crumbun running at http://${server.hostname}:${server.port}`);Expected app shape:
public/
src/
api/
views/
export.ts
server.tsAdd src/views/index.pug:
h1 Hello from crumbunRun it:
bun --hot src/server.tsFirst Route
src/api/story/[id]/page.ts
import type { PageContext } from "crumbun";
export function GET({ params, render }: PageContext) {
return render("story/story", {
title: `Story ${params.id}`,
});
}src/views/story/story.pug
h1= titleStatic Export
import { fileURLToPath } from "node:url";
import { exportStatic } from "crumbun";
const result = await exportStatic({
root: fileURLToPath(new URL("..", import.meta.url)),
paths: ["/", "/story/first-light"],
});
console.log(`Exported ${result.outDir}`);Conventions
src/api/**/page.tscreates routes.[id]becomesparams.id.(group)keeps a folder out of the URL.src/views/index.pugrendersGET /when no page route matches.render("story/story")renderssrc/views/story/story.pug.public/is served from/.src/views/**/*.cssandsrc/views/**/*.scssare served from/_crumbun(SCSS is compiled on the fly).- A view's own stylesheet is auto-linked:
src/views/story/story.scssis injected as/_crumbun/story/story.csswhen you renderstory/story. Opt out withrender(view, { css: false }). You can also link the source directly (/_crumbun/story/story.scss) in dev. src/views/_layout.pugcan wrap rendered views.src/views/_error.pugcan render 404 and 500 pages.
Handler Helpers
json(value, init?)returns JSON.redirect(path, status?)returns a redirect response.cookies.get/set/delete/allreads and writes cookies.highlightCode(source, language?)is available in Pug views and fromcrumbun.env(key, fallback?)readsBun.env.spa: truemakes unknownGETrequests fall back toindex.pug.
