create-nifra 0.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/dist/agents.d.ts +22 -0
  4. package/dist/agents.d.ts.map +1 -0
  5. package/dist/agents.js +259 -0
  6. package/dist/agents.js.map +1 -0
  7. package/dist/auth.d.ts +30 -0
  8. package/dist/auth.d.ts.map +1 -0
  9. package/dist/auth.js +90 -0
  10. package/dist/auth.js.map +1 -0
  11. package/dist/cli.d.ts +101 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +450 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/db.d.ts +39 -0
  16. package/dist/db.d.ts.map +1 -0
  17. package/dist/db.js +467 -0
  18. package/dist/db.js.map +1 -0
  19. package/package.json +50 -0
  20. package/template/README.md +24 -0
  21. package/template/gitignore +6 -0
  22. package/template/package.json +20 -0
  23. package/template/src/app.test.ts +8 -0
  24. package/template/src/app.ts +8 -0
  25. package/template/src/index.ts +5 -0
  26. package/template/tsconfig.json +16 -0
  27. package/template-isr/README.md +46 -0
  28. package/template-isr/backend.ts +12 -0
  29. package/template-isr/build.ts +23 -0
  30. package/template-isr/gitignore +7 -0
  31. package/template-isr/package.json +24 -0
  32. package/template-isr/routes/_404.tsx +10 -0
  33. package/template-isr/routes/_layout.tsx +18 -0
  34. package/template-isr/routes/index.tsx +34 -0
  35. package/template-isr/server.ts +56 -0
  36. package/template-isr/tsconfig.json +28 -0
  37. package/template-isr/worker.ts +52 -0
  38. package/template-isr/wrangler.toml +20 -0
  39. package/template-site/.dockerignore +14 -0
  40. package/template-site/Dockerfile +20 -0
  41. package/template-site/README.md +44 -0
  42. package/template-site/_worker.ts +17 -0
  43. package/template-site/backend.ts +12 -0
  44. package/template-site/build-bun.ts +27 -0
  45. package/template-site/build-deno.ts +25 -0
  46. package/template-site/build-node.ts +26 -0
  47. package/template-site/build-vercel.ts +45 -0
  48. package/template-site/build.ts +29 -0
  49. package/template-site/deno.json +7 -0
  50. package/template-site/framework.ts +6 -0
  51. package/template-site/gitignore +16 -0
  52. package/template-site/nifra.config.ts +9 -0
  53. package/template-site/package.json +37 -0
  54. package/template-site/routes/_404.tsx +20 -0
  55. package/template-site/routes/_layout.tsx +40 -0
  56. package/template-site/routes/index.tsx +53 -0
  57. package/template-site/server-bun.ts +35 -0
  58. package/template-site/server-deno.ts +38 -0
  59. package/template-site/server-node.ts +40 -0
  60. package/template-site/server-vercel.ts +17 -0
  61. package/template-site/tsconfig.json +37 -0
  62. package/template-site/wrangler.toml +4 -0
  63. package/template-site-preact/.dockerignore +14 -0
  64. package/template-site-preact/Dockerfile +20 -0
  65. package/template-site-preact/README.md +43 -0
  66. package/template-site-preact/_worker.ts +17 -0
  67. package/template-site-preact/backend.ts +12 -0
  68. package/template-site-preact/build-bun.ts +27 -0
  69. package/template-site-preact/build-deno.ts +25 -0
  70. package/template-site-preact/build-node.ts +26 -0
  71. package/template-site-preact/build-vercel.ts +45 -0
  72. package/template-site-preact/build.ts +29 -0
  73. package/template-site-preact/deno.json +7 -0
  74. package/template-site-preact/framework.ts +6 -0
  75. package/template-site-preact/gitignore +16 -0
  76. package/template-site-preact/nifra.config.ts +9 -0
  77. package/template-site-preact/package.json +34 -0
  78. package/template-site-preact/routes/_404.tsx +20 -0
  79. package/template-site-preact/routes/_layout.tsx +40 -0
  80. package/template-site-preact/routes/index.tsx +53 -0
  81. package/template-site-preact/server-bun.ts +35 -0
  82. package/template-site-preact/server-deno.ts +38 -0
  83. package/template-site-preact/server-node.ts +40 -0
  84. package/template-site-preact/server-vercel.ts +17 -0
  85. package/template-site-preact/tsconfig.json +38 -0
  86. package/template-site-preact/wrangler.toml +4 -0
  87. package/template-site-solid/.dockerignore +14 -0
  88. package/template-site-solid/Dockerfile +20 -0
  89. package/template-site-solid/README.md +43 -0
  90. package/template-site-solid/_worker.ts +17 -0
  91. package/template-site-solid/backend.ts +12 -0
  92. package/template-site-solid/build-bun.ts +33 -0
  93. package/template-site-solid/build-deno.ts +32 -0
  94. package/template-site-solid/build-node.ts +33 -0
  95. package/template-site-solid/build-vercel.ts +47 -0
  96. package/template-site-solid/build.ts +36 -0
  97. package/template-site-solid/deno.json +7 -0
  98. package/template-site-solid/framework.ts +6 -0
  99. package/template-site-solid/gitignore +16 -0
  100. package/template-site-solid/nifra.config.ts +14 -0
  101. package/template-site-solid/package.json +34 -0
  102. package/template-site-solid/routes/_404.tsx +20 -0
  103. package/template-site-solid/routes/_layout.tsx +39 -0
  104. package/template-site-solid/routes/index.tsx +53 -0
  105. package/template-site-solid/server-bun.ts +35 -0
  106. package/template-site-solid/server-deno.ts +38 -0
  107. package/template-site-solid/server-node.ts +40 -0
  108. package/template-site-solid/server-vercel.ts +17 -0
  109. package/template-site-solid/tsconfig.json +38 -0
  110. package/template-site-solid/wrangler.toml +4 -0
  111. package/template-site-svelte/.dockerignore +14 -0
  112. package/template-site-svelte/Dockerfile +20 -0
  113. package/template-site-svelte/README.md +45 -0
  114. package/template-site-svelte/_worker.ts +17 -0
  115. package/template-site-svelte/backend.ts +12 -0
  116. package/template-site-svelte/build-bun.ts +32 -0
  117. package/template-site-svelte/build-deno.ts +31 -0
  118. package/template-site-svelte/build-node.ts +32 -0
  119. package/template-site-svelte/build-vercel.ts +46 -0
  120. package/template-site-svelte/build.ts +35 -0
  121. package/template-site-svelte/deno.json +7 -0
  122. package/template-site-svelte/framework.ts +6 -0
  123. package/template-site-svelte/gitignore +16 -0
  124. package/template-site-svelte/nifra.config.ts +13 -0
  125. package/template-site-svelte/package.json +34 -0
  126. package/template-site-svelte/routes/_404.svelte +16 -0
  127. package/template-site-svelte/routes/_layout.svelte +35 -0
  128. package/template-site-svelte/routes/index.svelte +47 -0
  129. package/template-site-svelte/server-bun.ts +35 -0
  130. package/template-site-svelte/server-deno.ts +38 -0
  131. package/template-site-svelte/server-node.ts +40 -0
  132. package/template-site-svelte/server-vercel.ts +17 -0
  133. package/template-site-svelte/tsconfig.json +37 -0
  134. package/template-site-svelte/wrangler.toml +4 -0
  135. package/template-site-vue/.dockerignore +14 -0
  136. package/template-site-vue/Dockerfile +20 -0
  137. package/template-site-vue/README.md +45 -0
  138. package/template-site-vue/_worker.ts +17 -0
  139. package/template-site-vue/backend.ts +12 -0
  140. package/template-site-vue/build-bun.ts +37 -0
  141. package/template-site-vue/build-deno.ts +36 -0
  142. package/template-site-vue/build-node.ts +37 -0
  143. package/template-site-vue/build-vercel.ts +54 -0
  144. package/template-site-vue/build.ts +40 -0
  145. package/template-site-vue/deno.json +7 -0
  146. package/template-site-vue/framework.ts +6 -0
  147. package/template-site-vue/gitignore +16 -0
  148. package/template-site-vue/nifra.config.ts +19 -0
  149. package/template-site-vue/package.json +35 -0
  150. package/template-site-vue/routes/_404.vue +18 -0
  151. package/template-site-vue/routes/_layout.vue +40 -0
  152. package/template-site-vue/routes/index.vue +56 -0
  153. package/template-site-vue/server-bun.ts +35 -0
  154. package/template-site-vue/server-deno.ts +38 -0
  155. package/template-site-vue/server-node.ts +40 -0
  156. package/template-site-vue/server-vercel.ts +17 -0
  157. package/template-site-vue/tsconfig.json +37 -0
  158. package/template-site-vue/wrangler.toml +4 -0
@@ -0,0 +1,20 @@
1
+ import Layout from "./_layout"
2
+
3
+ export const meta = { title: "Not found" }
4
+
5
+ // nifra's catch-all renders _404 without the layout chain, so it wraps itself in the root Layout.
6
+ export default function NotFound() {
7
+ return (
8
+ <Layout>
9
+ <section className="hero">
10
+ <h1>
11
+ <span className="grad">404</span>
12
+ </h1>
13
+ <p>That page doesn't exist.</p>
14
+ <a className="btn" href="/">
15
+ ← Back home
16
+ </a>
17
+ </section>
18
+ </Layout>
19
+ )
20
+ }
@@ -0,0 +1,40 @@
1
+ import type { ReactNode } from "react"
2
+
3
+ const css = `
4
+ :root { --bg:#0a0a0f; --panel:#14141c; --border:#26263a; --fg:#e8e8f0; --muted:#9a9ab0; --accent:#7c5cff; --accent2:#00d4ff; }
5
+ * { box-sizing: border-box; } html { color-scheme: dark; }
6
+ body { margin:0; background:var(--bg); color:var(--fg); font:16px/1.6 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif; -webkit-font-smoothing:antialiased; }
7
+ a { color:var(--accent2); text-decoration:none; } a:hover { text-decoration:underline; }
8
+ .wrap { max-width:840px; margin:0 auto; padding:0 24px; }
9
+ header.site { border-bottom:1px solid var(--border); } header.site .wrap { display:flex; align-items:center; justify-content:space-between; height:62px; }
10
+ .logo, .logo b { font-weight:800; font-size:20px; } .logo b { background:linear-gradient(90deg,var(--accent),var(--accent2)); -webkit-background-clip:text; background-clip:text; color:transparent; }
11
+ .hero { text-align:center; padding:80px 0 56px; }
12
+ .hero h1 { font-size:clamp(36px,6vw,56px); line-height:1.05; margin:0 0 16px; letter-spacing:-0.03em; }
13
+ .hero h1 .grad { background:linear-gradient(90deg,var(--accent),var(--accent2)); -webkit-background-clip:text; background-clip:text; color:transparent; }
14
+ .hero p { font-size:19px; color:var(--muted); max-width:560px; margin:0 auto 28px; }
15
+ .card { background:var(--panel); border:1px solid var(--border); border-radius:14px; padding:24px 28px; display:flex; align-items:center; justify-content:space-between; gap:24px; flex-wrap:wrap; }
16
+ .card h3 { margin:0 0 4px; } .card p { margin:0; color:var(--muted); font-size:14px; }
17
+ .count { font-size:34px; font-weight:800; font-variant-numeric:tabular-nums; min-width:44px; text-align:center; background:linear-gradient(90deg,var(--accent),var(--accent2)); -webkit-background-clip:text; background-clip:text; color:transparent; }
18
+ .btn { background:linear-gradient(90deg,var(--accent),var(--accent2)); color:#0a0a0f; font:inherit; font-weight:700; border:none; cursor:pointer; padding:11px 20px; border-radius:10px; }
19
+ footer.site { border-top:1px solid var(--border); color:var(--muted); font-size:14px; } footer.site .wrap { padding:24px; }
20
+ `.trim()
21
+
22
+ export default function Layout(props: { children?: ReactNode }) {
23
+ return (
24
+ <div id="app">
25
+ <style>{css}</style>
26
+ <header className="site">
27
+ <div className="wrap">
28
+ <a href="/" className="logo">
29
+ <b>nifra</b>
30
+ </a>
31
+ <a href="https://github.com">GitHub</a>
32
+ </div>
33
+ </header>
34
+ <main className="wrap">{props.children}</main>
35
+ <footer className="site">
36
+ <div className="wrap">Built with nifra</div>
37
+ </footer>
38
+ </div>
39
+ )
40
+ }
@@ -0,0 +1,53 @@
1
+ import type { ActionArgs, LoaderArgs, LoaderData } from "@nifrajs/client"
2
+ import type { backend } from "../backend"
3
+
4
+ export const meta = {
5
+ title: "nifra site",
6
+ meta: [{ name: "description", content: "A nifra + React SSR site, deployable to every runtime." }],
7
+ }
8
+
9
+ // Loader runs on the server (in-process during SSR). The action handles the form POST; after a
10
+ // client submit the loader revalidates with no full reload (progressive enhancement).
11
+ export async function loader({ api }: LoaderArgs<typeof backend>) {
12
+ const res = await api.count.get()
13
+ return { count: res.data?.count ?? 0 }
14
+ }
15
+
16
+ export async function action({ api }: ActionArgs<typeof backend>) {
17
+ await api.count.post()
18
+ return { ok: true }
19
+ }
20
+
21
+ export default function Home(props: { data: LoaderData<typeof loader> }) {
22
+ return (
23
+ <>
24
+ <section className="hero">
25
+ <h1>
26
+ Your nifra app,
27
+ <br />
28
+ <span className="grad">everywhere.</span>
29
+ </h1>
30
+ <p>
31
+ SSR + hydration, end-to-end types, React. One source — deploy to Cloudflare Pages, Node,
32
+ Deno, or Vercel Edge. Edit <code>routes/index.tsx</code> to begin.
33
+ </p>
34
+ </section>
35
+
36
+ <div className="card">
37
+ <div>
38
+ <h3>Live full-stack loop</h3>
39
+ <p>
40
+ Count is rendered by a typed <code>loader</code>, incremented by an <code>action</code>,
41
+ revalidated with no full reload.
42
+ </p>
43
+ </div>
44
+ <form method="post" style={{ display: "flex", alignItems: "center", gap: 16 }}>
45
+ <span className="count">{props.data.count}</span>
46
+ <button className="btn" type="submit">
47
+ increment →
48
+ </button>
49
+ </form>
50
+ </div>
51
+ </>
52
+ )
53
+ }
@@ -0,0 +1,35 @@
1
+ import { inProcessClient } from "@nifrajs/client"
2
+ import { createWebApp } from "@nifrajs/web"
3
+ import { backend } from "./backend"
4
+ import { adapter } from "./framework"
5
+ import { clientEntry, manifest } from "./server-manifest"
6
+
7
+ const app = createWebApp({
8
+ adapter,
9
+ manifest,
10
+ clientEntry,
11
+ api: inProcessClient(backend),
12
+ title: "nifra site",
13
+ })
14
+
15
+ // Bun (nifra's flagship runtime): Bun.serve handles app.fetch; serve the client bundle (/assets/*)
16
+ // from disk with Bun.file. Assets live next to this file in the built dist-bun/ output.
17
+ const ASSETS = new URL("./assets/", import.meta.url)
18
+ const TYPES: Readonly<Record<string, string>> = { js: "text/javascript", css: "text/css" }
19
+
20
+ const server = Bun.serve({
21
+ port: Number(Bun.env.PORT ?? 3000),
22
+ async fetch(req) {
23
+ const { pathname } = new URL(req.url)
24
+ if (pathname.startsWith("/assets/")) {
25
+ const name = pathname.slice("/assets/".length)
26
+ if (!/^[A-Za-z0-9._-]+$/.test(name)) return new Response("bad request", { status: 400 })
27
+ const file = Bun.file(new URL(name, ASSETS))
28
+ if (!(await file.exists())) return new Response("not found", { status: 404 })
29
+ const ext = name.slice(name.lastIndexOf(".") + 1)
30
+ return new Response(file, { headers: { "content-type": TYPES[ext] ?? "application/octet-stream" } })
31
+ }
32
+ return app.fetch(req)
33
+ },
34
+ })
35
+ console.log(`nifra (Bun) → http://localhost:${server.port}`)
@@ -0,0 +1,38 @@
1
+ import { inProcessClient } from "@nifrajs/client"
2
+ import { serve } from "@nifrajs/deno"
3
+ import { createWebApp } from "@nifrajs/web"
4
+ import { backend } from "./backend"
5
+ import { adapter } from "./framework"
6
+ import { clientEntry, manifest } from "./server-manifest"
7
+
8
+ const app = createWebApp({
9
+ adapter,
10
+ manifest,
11
+ clientEntry,
12
+ api: inProcessClient(backend),
13
+ title: "nifra site",
14
+ })
15
+
16
+ const ASSETS = new URL("./assets/", import.meta.url)
17
+ const TYPES: Readonly<Record<string, string>> = { js: "text/javascript", css: "text/css" }
18
+
19
+ await serve(
20
+ {
21
+ async fetch(req) {
22
+ const { pathname } = new URL(req.url)
23
+ if (pathname.startsWith("/assets/")) {
24
+ const name = pathname.slice("/assets/".length)
25
+ if (!/^[A-Za-z0-9._-]+$/.test(name)) return new Response("bad request", { status: 400 })
26
+ try {
27
+ const body = await Deno.readFile(new URL(name, ASSETS))
28
+ const ext = name.slice(name.lastIndexOf(".") + 1)
29
+ return new Response(body, { headers: { "content-type": TYPES[ext] ?? "application/octet-stream" } })
30
+ } catch {
31
+ return new Response("not found", { status: 404 })
32
+ }
33
+ }
34
+ return app.fetch(req)
35
+ },
36
+ },
37
+ { port: Number(Deno.env.get("PORT") ?? "3000") },
38
+ )
@@ -0,0 +1,40 @@
1
+ import { readFile } from "node:fs/promises"
2
+ import { inProcessClient } from "@nifrajs/client"
3
+ import { serve } from "@nifrajs/node"
4
+ import { createWebApp } from "@nifrajs/web"
5
+ import { backend } from "./backend"
6
+ import { adapter } from "./framework"
7
+ import { clientEntry, manifest } from "./server-manifest"
8
+
9
+ const app = createWebApp({
10
+ adapter,
11
+ manifest,
12
+ clientEntry,
13
+ api: inProcessClient(backend),
14
+ title: "nifra site",
15
+ })
16
+
17
+ // @nifrajs/node serves app.fetch only — so serve /assets/* (the client bundle) from disk here.
18
+ const ASSETS = new URL("./assets/", import.meta.url)
19
+ const TYPES: Readonly<Record<string, string>> = { js: "text/javascript", css: "text/css" }
20
+
21
+ await serve(
22
+ {
23
+ async fetch(req) {
24
+ const { pathname } = new URL(req.url)
25
+ if (pathname.startsWith("/assets/")) {
26
+ const name = pathname.slice("/assets/".length)
27
+ if (!/^[A-Za-z0-9._-]+$/.test(name)) return new Response("bad request", { status: 400 })
28
+ try {
29
+ const body = await readFile(new URL(name, ASSETS))
30
+ const ext = name.slice(name.lastIndexOf(".") + 1)
31
+ return new Response(body, { headers: { "content-type": TYPES[ext] ?? "application/octet-stream" } })
32
+ } catch {
33
+ return new Response("not found", { status: 404 })
34
+ }
35
+ }
36
+ return app.fetch(req)
37
+ },
38
+ },
39
+ { port: Number(process.env.PORT ?? 3000) },
40
+ )
@@ -0,0 +1,17 @@
1
+ import { inProcessClient } from "@nifrajs/client"
2
+ import { createWebApp } from "@nifrajs/web"
3
+ import { backend } from "./backend"
4
+ import { adapter } from "./framework"
5
+ import { clientEntry, manifest } from "./server-manifest"
6
+
7
+ const app = createWebApp({
8
+ adapter,
9
+ manifest,
10
+ clientEntry,
11
+ api: inProcessClient(backend),
12
+ title: "nifra site",
13
+ })
14
+
15
+ // Vercel Edge Function — Vercel serves /assets/* from its CDN, so this only SSRs page routes.
16
+ export const config = { runtime: "edge" }
17
+ export default (req: Request): Response | Promise<Response> => app.fetch(req)
@@ -0,0 +1,37 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "jsx": "react-jsx",
8
+ "strict": true,
9
+ "noUncheckedIndexedAccess": true,
10
+ "skipLibCheck": true,
11
+ "noEmit": true,
12
+ "verbatimModuleSyntax": true,
13
+ "types": ["react", "react-dom"]
14
+ },
15
+ "include": ["**/*.ts", "**/*.tsx"],
16
+ "exclude": [
17
+ "node_modules",
18
+ "dist",
19
+ "dist-bun",
20
+ "dist-node",
21
+ "dist-deno",
22
+ "dist-vercel",
23
+ ".nifra",
24
+ ".wrangler",
25
+ "server-manifest.ts",
26
+ "server-bun.ts",
27
+ "server-node.ts",
28
+ "server-deno.ts",
29
+ "server-vercel.ts",
30
+ "_worker.ts",
31
+ "build.ts",
32
+ "build-bun.ts",
33
+ "build-node.ts",
34
+ "build-deno.ts",
35
+ "build-vercel.ts"
36
+ ]
37
+ }
@@ -0,0 +1,4 @@
1
+ name = "nifra-site"
2
+ pages_build_output_dir = "dist"
3
+ compatibility_date = "2025-01-01"
4
+ compatibility_flags = ["nodejs_compat"]
@@ -0,0 +1,14 @@
1
+ node_modules
2
+ dist
3
+ dist-node
4
+ dist-bun
5
+ dist-deno
6
+ .vercel
7
+ .build
8
+ .build-node
9
+ .build-bun
10
+ .build-deno
11
+ .build-vercel
12
+ .wrangler
13
+ .git
14
+ *.log
@@ -0,0 +1,20 @@
1
+ # nifra on Node, containerized. Build with Bun (nifra's build toolchain), then run the self-contained
2
+ # bundle on a slim Node image — the final image carries no build tools or node_modules.
3
+ # docker build -t my-nifra-app .
4
+ # docker run -p 3000:3000 my-nifra-app
5
+ FROM oven/bun:1 AS build
6
+ WORKDIR /app
7
+ # Copy manifests first so the install layer caches across source-only changes.
8
+ COPY package.json bun.lock* ./
9
+ RUN bun install
10
+ COPY . .
11
+ RUN bun run build:node
12
+
13
+ FROM node:22-slim AS run
14
+ WORKDIR /app
15
+ ENV NODE_ENV=production
16
+ ENV PORT=3000
17
+ # build:node emits a self-contained server-bundle + the client assets it serves from disk.
18
+ COPY --from=build /app/dist-node ./dist-node
19
+ EXPOSE 3000
20
+ CMD ["node", "dist-node/server-node.js"]
@@ -0,0 +1,43 @@
1
+ # nifra site (Preact)
2
+
3
+ A nifra + **Preact** SSR site — file-based routes, typed loaders/actions, hydration — that deploys to
4
+ **Bun, Node (Docker), Deno Deploy, Cloudflare Pages, and Vercel Edge from one source**. `app.fetch`
5
+ is Web-standard, so only the server entry + build target differ per platform.
6
+
7
+ ```sh
8
+ bun install
9
+ bun run dev # nifra dev → true-HMR dev server (Vite + nifra SSR) at http://localhost:3000
10
+ bun run preview # wrangler pages dev dist → preview the built Cloudflare bundle (run `bun run build` first)
11
+ ```
12
+
13
+ Routes are Preact function components (JSX, via `jsxImportSource: "preact"`) under `routes/` —
14
+ `index.tsx` (landing + a live loader/action counter), `_layout.tsx` (chrome), `_404.tsx`. The
15
+ frontend adapter is one line in `framework.ts`; data lives behind `backend.ts`.
16
+
17
+ ## Deploy — pick a target
18
+
19
+ | target | build | deploy |
20
+ | --- | --- | --- |
21
+ | **Bun** (flagship) | `bun run build:bun` | `bun run start` — any host |
22
+ | **Node** | `bun run build:node` | `docker build -t app . && docker run -p 3000:3000 app` (or `bun run start:node`) |
23
+ | **Deno Deploy** | `bun run build:deno` | `deployctl deploy --prod --entrypoint=dist-deno/server-deno.js` |
24
+ | **Cloudflare Pages** | `bun run build` | `bun run deploy:cf` |
25
+ | **Vercel Edge** | `bun run build:vercel` | `bun run deploy:vercel` |
26
+
27
+ The routes, `backend.ts`, and the client bundle are shared; each `build*` script swaps `buildServer`'s
28
+ target/conditions and the server entry. nifra never enters your cloud credentials — it scaffolds the
29
+ configs (`Dockerfile`, `deno.json`, `wrangler.toml`, Vercel Build Output API); you run the vendor CLI.
30
+
31
+ ## Structure
32
+
33
+ ```
34
+ routes/ index.tsx (landing), _layout.tsx (chrome), _404.tsx
35
+ framework.ts the adapter (preactAdapter) — imported by the server entries (edge-bundlable)
36
+ nifra.config.ts the nifra CLI's dev/build config (adapter + clientModule + Vite plugin) — read by `nifra dev`
37
+ backend.ts your contract (loaders/actions call it in-process)
38
+ server-bun.ts Bun entry (Bun.serve) build-bun.ts → dist-bun/
39
+ _worker.ts Cloudflare Pages entry build.ts → dist/
40
+ server-node.ts Node entry (@nifrajs/node) build-node.ts → dist-node/ (Dockerfile)
41
+ server-deno.ts Deno entry (@nifrajs/deno) build-deno.ts → dist-deno/ (deno.json)
42
+ server-vercel.ts Vercel Edge function build-vercel.ts → .vercel/output/
43
+ ```
@@ -0,0 +1,17 @@
1
+ import { inProcessClient } from "@nifrajs/client"
2
+ import { toFetchHandler } from "@nifrajs/core"
3
+ import { createWebApp } from "@nifrajs/web"
4
+ import { backend } from "./backend"
5
+ import { adapter } from "./framework"
6
+ import { clientEntry, manifest } from "./server-manifest"
7
+
8
+ const app = createWebApp({
9
+ adapter,
10
+ manifest,
11
+ clientEntry,
12
+ api: inProcessClient(backend),
13
+ title: "nifra site",
14
+ })
15
+
16
+ // Cloudflare Pages: _routes.json serves /assets/* statically; everything else hits this (SSR).
17
+ export default toFetchHandler(app)
@@ -0,0 +1,12 @@
1
+ import { server } from "@nifrajs/core"
2
+
3
+ // Your backend contract — page loaders/actions call it in-process during SSR (no network). Replace
4
+ // the demo counter with real data (KV/D1/Postgres/…); on the edge, reach bindings via `c.env`.
5
+ let count = 0
6
+
7
+ export const backend = server()
8
+ .get("/count", () => ({ count }))
9
+ .post("/count", () => {
10
+ count += 1
11
+ return { count }
12
+ })
@@ -0,0 +1,27 @@
1
+ // Build for Bun (nifra's flagship runtime) → dist-bun/ (server-bun.js + client assets).
2
+ // `bun run build:bun`. Run: `bun dist-bun/server-bun.js`.
3
+ import { cpSync, mkdirSync, rmSync } from "node:fs"
4
+ import { buildClient, buildServer } from "@nifrajs/web/build"
5
+
6
+ const dir = import.meta.dir
7
+ const dist = `${dir}/dist-bun`
8
+ rmSync(dist, { recursive: true, force: true })
9
+ mkdirSync(`${dist}/assets`, { recursive: true })
10
+
11
+ const client = await buildClient({
12
+ routesDir: `${dir}/routes`,
13
+ outDir: `${dist}/assets`,
14
+ clientModule: "@nifrajs/web-preact/client",
15
+ conditions: ["bun", "browser"],
16
+ define: { "process.env.NODE_ENV": '"production"' },
17
+ })
18
+ const { worker } = await buildServer({
19
+ routesDir: `${dir}/routes`,
20
+ serverEntry: `${dir}/server-bun.ts`,
21
+ outDir: `${dir}/.build-bun`,
22
+ target: "bun",
23
+ clientEntry: client.entry,
24
+ })
25
+ cpSync(worker, `${dist}/server-bun.js`)
26
+ rmSync(`${dir}/.build-bun`, { recursive: true, force: true })
27
+ console.log("Bun output → dist-bun (run: bun dist-bun/server-bun.js)")
@@ -0,0 +1,25 @@
1
+ // Build for Deno → dist-deno/ (server-deno.js + client assets). `bun run build:deno`.
2
+ import { cpSync, mkdirSync, rmSync } from "node:fs"
3
+ import { buildClient, buildServer } from "@nifrajs/web/build"
4
+
5
+ const dir = import.meta.dir
6
+ const dist = `${dir}/dist-deno`
7
+ rmSync(dist, { recursive: true, force: true })
8
+ mkdirSync(`${dist}/assets`, { recursive: true })
9
+
10
+ const client = await buildClient({
11
+ routesDir: `${dir}/routes`,
12
+ outDir: `${dist}/assets`,
13
+ clientModule: "@nifrajs/web-preact/client",
14
+ conditions: ["bun", "browser"],
15
+ define: { "process.env.NODE_ENV": '"production"' },
16
+ })
17
+ const { worker } = await buildServer({
18
+ routesDir: `${dir}/routes`,
19
+ serverEntry: `${dir}/server-deno.ts`,
20
+ outDir: `${dir}/.build-deno`,
21
+ clientEntry: client.entry,
22
+ })
23
+ cpSync(worker, `${dist}/server-deno.js`)
24
+ rmSync(`${dir}/.build-deno`, { recursive: true, force: true })
25
+ console.log("Deno output → dist-deno (run: deno run -A dist-deno/server-deno.js)")
@@ -0,0 +1,26 @@
1
+ // Build for Node → dist-node/ (server-node.js + client assets). `bun run build:node`.
2
+ import { cpSync, mkdirSync, rmSync } from "node:fs"
3
+ import { buildClient, buildServer } from "@nifrajs/web/build"
4
+
5
+ const dir = import.meta.dir
6
+ const dist = `${dir}/dist-node`
7
+ rmSync(dist, { recursive: true, force: true })
8
+ mkdirSync(`${dist}/assets`, { recursive: true })
9
+
10
+ const client = await buildClient({
11
+ routesDir: `${dir}/routes`,
12
+ outDir: `${dist}/assets`,
13
+ clientModule: "@nifrajs/web-preact/client",
14
+ conditions: ["bun", "browser"],
15
+ define: { "process.env.NODE_ENV": '"production"' },
16
+ })
17
+ const { worker } = await buildServer({
18
+ routesDir: `${dir}/routes`,
19
+ serverEntry: `${dir}/server-node.ts`,
20
+ outDir: `${dir}/.build-node`,
21
+ target: "node",
22
+ clientEntry: client.entry,
23
+ })
24
+ cpSync(worker, `${dist}/server-node.js`)
25
+ rmSync(`${dir}/.build-node`, { recursive: true, force: true })
26
+ console.log("Node output → dist-node (run: node dist-node/server-node.js)")
@@ -0,0 +1,45 @@
1
+ // Build for Vercel, emitting Vercel's Build Output API v3 at .vercel/output/ so it deploys with no
2
+ // framework preset: `vercel deploy --prebuilt`. Layout:
3
+ // .vercel/output/config.json — serve static files, else SSR via the function
4
+ // .vercel/output/static/assets/<client bundle> — Vercel's CDN serves these directly
5
+ // .vercel/output/functions/index.func/index.js — the Edge SSR function (+ .vc-config.json)
6
+ import { cpSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
7
+ import { buildClient, buildServer } from "@nifrajs/web/build"
8
+
9
+ const dir = import.meta.dir
10
+ const out = `${dir}/.vercel/output`
11
+ const fn = `${out}/functions/index.func`
12
+ rmSync(`${dir}/.vercel`, { recursive: true, force: true })
13
+ mkdirSync(`${out}/static/assets`, { recursive: true })
14
+ mkdirSync(fn, { recursive: true })
15
+
16
+ const client = await buildClient({
17
+ routesDir: `${dir}/routes`,
18
+ outDir: `${out}/static/assets`,
19
+ clientModule: "@nifrajs/web-preact/client",
20
+ conditions: ["bun", "browser"],
21
+ define: { "process.env.NODE_ENV": '"production"' },
22
+ })
23
+ const { worker } = await buildServer({
24
+ routesDir: `${dir}/routes`,
25
+ serverEntry: `${dir}/server-vercel.ts`,
26
+ outDir: `${dir}/.build-vercel`,
27
+ clientEntry: client.entry,
28
+ })
29
+ cpSync(worker, `${fn}/index.js`)
30
+ rmSync(`${dir}/.build-vercel`, { recursive: true, force: true })
31
+
32
+ // Build Output API v3: serve real files first (`handle: filesystem` → /assets/*), then SSR the rest.
33
+ writeFileSync(
34
+ `${fn}/.vc-config.json`,
35
+ `${JSON.stringify({ runtime: "edge", entrypoint: "index.js" }, null, 2)}\n`,
36
+ )
37
+ writeFileSync(
38
+ `${out}/config.json`,
39
+ `${JSON.stringify(
40
+ { version: 3, routes: [{ handle: "filesystem" }, { src: "/(.*)", dest: "/index" }] },
41
+ null,
42
+ 2,
43
+ )}\n`,
44
+ )
45
+ console.log("Vercel output → .vercel/output (deploy: vercel deploy --prebuilt)")
@@ -0,0 +1,29 @@
1
+ // Build for Cloudflare Pages → dist/ (_worker.js + _routes.json + client assets). `bun run build`.
2
+ import { cpSync, mkdirSync, rmSync, writeFileSync } from "node:fs"
3
+ import { buildClient, buildServer } from "@nifrajs/web/build"
4
+
5
+ const dir = import.meta.dir
6
+ const dist = `${dir}/dist`
7
+ rmSync(dist, { recursive: true, force: true })
8
+ mkdirSync(`${dist}/assets`, { recursive: true })
9
+
10
+ const client = await buildClient({
11
+ routesDir: `${dir}/routes`,
12
+ outDir: `${dist}/assets`,
13
+ clientModule: "@nifrajs/web-preact/client",
14
+ conditions: ["bun", "browser"],
15
+ define: { "process.env.NODE_ENV": '"production"' },
16
+ })
17
+ const { worker } = await buildServer({
18
+ routesDir: `${dir}/routes`,
19
+ serverEntry: `${dir}/_worker.ts`,
20
+ outDir: `${dir}/.build`,
21
+ clientEntry: client.entry,
22
+ })
23
+ cpSync(worker, `${dist}/_worker.js`)
24
+ rmSync(`${dir}/.build`, { recursive: true, force: true })
25
+ writeFileSync(
26
+ `${dist}/_routes.json`,
27
+ `${JSON.stringify({ version: 1, include: ["/*"], exclude: ["/assets/*"] }, null, 2)}\n`,
28
+ )
29
+ console.log("Cloudflare Pages output → dist (deploy: wrangler pages deploy dist)")
@@ -0,0 +1,7 @@
1
+ {
2
+ "tasks": {
3
+ "build": "bun run build-deno.ts",
4
+ "start": "deno run --allow-net --allow-read --allow-env dist-deno/server-deno.js"
5
+ },
6
+ "//": "Build with Bun (nifra's toolchain), run/deploy the self-contained bundle on Deno. Deploy to Deno Deploy: deployctl deploy --prod --entrypoint=dist-deno/server-deno.js"
7
+ }
@@ -0,0 +1,6 @@
1
+ // The frontend adapter for this app. `create-nifra --framework <react|preact|vue|solid|svelte>` swaps
2
+ // this one line (and the routes + build config); every server entry imports the adapter from here, so
3
+ // they stay framework-agnostic.
4
+ import { preactAdapter } from "@nifrajs/web-preact"
5
+
6
+ export const adapter = preactAdapter
@@ -0,0 +1,16 @@
1
+ node_modules
2
+ dist
3
+ dist-bun
4
+ dist-node
5
+ dist-deno
6
+ .vercel
7
+ .build
8
+ .build-bun
9
+ .build-node
10
+ .build-deno
11
+ .build-vercel
12
+ .wrangler
13
+ # generated by buildServer next to the entry
14
+ server-manifest.ts
15
+ # generated by `nifra dev` (the Vite dev client entry) at the project root
16
+ .nifra-vite-entry.tsx
@@ -0,0 +1,9 @@
1
+ // The nifra CLI's config — read by `nifra dev|build|start`. Separate from `framework.ts` (which the
2
+ // edge/server entries import, so it must stay edge-bundlable): THIS file is imported only by the CLI
3
+ // (which runs on Bun), so it's the place for dev/build tooling like the Vite plugin. Preact JSX is
4
+ // Bun-native, so the only extra is the Vite plugin for dev HMR (`@preact/preset-vite` = prefresh).
5
+ import preact from "@preact/preset-vite"
6
+
7
+ export { adapter } from "./framework"
8
+ export const clientModule = "@nifrajs/web-preact/client"
9
+ export const vitePlugins = [preact()]
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "nifra-site",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "private": true,
6
+ "scripts": {
7
+ "dev": "nifra dev",
8
+ "preview": "bunx wrangler pages dev dist",
9
+ "build": "bun run build.ts",
10
+ "build:bun": "bun run build-bun.ts",
11
+ "build:node": "bun run build-node.ts",
12
+ "build:deno": "bun run build-deno.ts",
13
+ "build:vercel": "bun run build-vercel.ts",
14
+ "start": "bun dist-bun/server-bun.js",
15
+ "start:node": "node dist-node/server-node.js",
16
+ "deploy:cf": "wrangler pages deploy dist",
17
+ "deploy:vercel": "vercel deploy --prebuilt"
18
+ },
19
+ "dependencies": {
20
+ "@nifrajs/client": "^0.1.0",
21
+ "@nifrajs/core": "^0.1.0",
22
+ "@nifrajs/deno": "^0.1.0",
23
+ "@nifrajs/node": "^0.1.0",
24
+ "@nifrajs/web": "^0.1.0",
25
+ "@nifrajs/web-preact": "^0.1.0",
26
+ "preact": "^10.25.0"
27
+ },
28
+ "devDependencies": {
29
+ "@preact/preset-vite": "^2.9.0",
30
+ "@nifrajs/cli": "^0.1.0",
31
+ "typescript": "^6.0.3",
32
+ "vite": "^8.0.0"
33
+ }
34
+ }