defuss-ssg 0.6.3 → 0.7.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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ Static site generation, request-time dev SSR, file-based endpoints, and producti
8
8
  - `build` renders static HTML, bundles client components, compiles endpoints, and copies assets.
9
9
  - `serve` serves built output with `defuss-express`, plus dynamic endpoints and optional RPC.
10
10
 
11
- Use Bun for package management. The published package targets Node `^20.19.0 || >=22.12.0`.
11
+ Use Bun for package management. The published package and the container runtime both target Node `^20.19.0 || >=22.12.0`.
12
12
 
13
13
  ## What It Supports
14
14
 
@@ -62,6 +62,7 @@ Minimal config:
62
62
  ```ts
63
63
  import { rehypePlugins, remarkPlugins, type SsgConfig } from "defuss-ssg";
64
64
 
65
+ // all of the fields are optional; you can also skip the file itself!
65
66
  const config: SsgConfig = {
66
67
  pages: "pages",
67
68
  output: "dist",
@@ -72,11 +73,44 @@ const config: SsgConfig = {
72
73
  remarkPlugins: [...remarkPlugins],
73
74
  rehypePlugins: [...rehypePlugins],
74
75
  rpc: true,
76
+ // e.g. set defuss-ssg to use podman even if docker is available
77
+ containerRuntime: "docker",
78
+ // override Vite config
79
+ viteConfig: {
80
+ ...
81
+ },
82
+ } satisfies SsgConfig;
83
+
84
+ export default config;
85
+ ```
86
+
87
+ `containerRuntime` forces `docker` or `podman` for `docker-*` commands. `viteConfig` is merged into defuss-ssg's internal Vite config for both `dev` and `build`, so you can add aliases, plugins, server options, and similar Vite settings from `config.ts`.
88
+
89
+ If you need to extend the current defuss-ssg Vite config instead of only passing a patch object, import it from the virtual module and merge from there:
90
+
91
+ ```ts
92
+ import { mergeConfig } from "vite";
93
+ import { viteConfig as currentViteConfig } from "virtual:defuss-ssg/config";
94
+
95
+ const config: SsgConfig = {
96
+ viteConfig: mergeConfig(currentViteConfig, {
97
+ resolve: {
98
+ alias: {
99
+ "@app": new URL("./src", import.meta.url).pathname,
100
+ },
101
+ },
102
+ server: {
103
+ // your custom domain, headers etc.
104
+ allowedHosts: ["example-ssg.demo.defuss.tech"],
105
+ },
106
+ }),
75
107
  };
76
108
 
77
109
  export default config;
78
110
  ```
79
111
 
112
+ The virtual module resolves to the current internal `defuss-ssg` Vite config, so you can also inspect or extend existing plugin arrays and nested Vite settings without re-creating them manually.
113
+
80
114
  Example page:
81
115
 
82
116
  ```mdx
@@ -96,8 +130,16 @@ This page uses MDX, frontmatter, and a defuss component.
96
130
  Example component:
97
131
 
98
132
  ```tsx
99
- export function Button({ label }: { label: string }) {
100
- return <button type="button">{label}</button>;
133
+ import type { Props } from "defuss";
134
+
135
+ export interface ButtonProps extends Props {
136
+ label: string;
137
+ }
138
+
139
+ export function Button({ label }: ButtonProps) {
140
+ return (
141
+ <button type="button">{label}</button>
142
+ );
101
143
  }
102
144
  ```
103
145
 
@@ -121,6 +163,61 @@ defuss-ssg serve ./my-site
121
163
 
122
164
  `serve` expects existing build output in `dist/`, so run `build` first.
123
165
 
166
+ For checked-out, unpublished, or locally linked package development use e.g.:
167
+
168
+ ```bash
169
+ node ./dist/cli.mjs dev ../../examples/with-dson/ --port 3010
170
+ ```
171
+
172
+
173
+ ## Production Deployment
174
+
175
+ `defuss-ssg` supports `podman` and `docker` for production deployment.
176
+
177
+ The primary container workflow is built into the CLI:
178
+
179
+ ```bash
180
+ bunx defuss-ssg container-dev ./my-site
181
+ bunx defuss-ssg container-build ./my-site
182
+ bunx defuss-ssg container-serve ./my-site --multicore
183
+ ```
184
+
185
+ When you are working from this monorepo before the next npm publish, use the built local CLI instead of `bunx defuss-ssg`. `bunx defuss-ssg` resolves the last published package, so it will not see unreleased `docker-*` commands from this checkout:
186
+
187
+ ```bash
188
+ cd packages/ssg
189
+ bun run build
190
+ node ./dist/cli.mjs container-dev ../../example-ssg --port 3111 --container-args --network host
191
+ ```
192
+
193
+ Each `docker-*` command writes a temporary Dockerfile, builds a local `defuss-ssg` image, mounts your project at `/workspace`, mounts a deterministic container-managed `/workspace/node_modules` volume, and then runs the matching inner `defuss-ssg` command. The mounted project still owns its dependency graph: the container reads that project's `package.json`, uses its declared package manager, installs the project's dependencies, and then starts `dev`, `build`, or `serve`.
194
+
195
+ `container-dev` and `container-serve` automatically bind the inner service to `0.0.0.0` and publish the selected port. One published port is enough even with `--multicore`; `defuss-express` keeps worker ports internal and load-balances behind the public port.
196
+
197
+ Runtime selection:
198
+
199
+ - `docker` is preferred automatically when available
200
+ - `podman` is used automatically when Docker is unavailable
201
+ - Set `containerRuntime` in `config.ts` to force one runtime explicitly
202
+
203
+ ```ts
204
+ export default {
205
+ containerRuntime: "podman",
206
+ };
207
+ ```
208
+
209
+ Outer container runtime arguments can be forwarded with `--container-args`. Everything after that marker is appended to the outer `docker run` or `podman run` call, while the arguments before it still go to the inner `defuss-ssg` command:
210
+
211
+ ```bash
212
+ bunx defuss-ssg container-dev ./my-site --port 3000 --container-args --network host
213
+ bunx defuss-ssg container-serve ./my-site --multicore --container-args --env NODE_ENV=production
214
+ ```
215
+
216
+ Good to know:
217
+ - The container runs the same `setup()` flow as local CLI usage.
218
+ - Use the generated container-managed `/workspace/node_modules` volume instead of bind-mounting host `node_modules` across OS or architecture boundaries.
219
+ - For manual container management, a static, minimal Dockerfile is available as `Dockerfile` too.
220
+
124
221
  ## How It Works
125
222
 
126
223
  ### Dev Mode
@@ -137,6 +234,45 @@ By default, the CLI keeps `dist/` refreshed during dev as a compatibility fallba
137
234
 
138
235
  `defuss-ssg serve` reads the built output from `dist/` and serves it with `defuss-express`. Dynamic endpoint modules are registered at runtime, and `rpc.ts` or `rpc.js` is compiled and initialized automatically when RPC is enabled and `defuss-rpc` is installed.
139
236
 
237
+ ## Content Discovery
238
+
239
+ For generation-time listings such as blog archives, `defuss-ssg` now exposes a small `glob()` API.
240
+
241
+ Use the virtual module inside MDX or other code that Vite evaluates for SSR:
242
+
243
+ ```ts
244
+ import { glob } from "virtual:defuss-ssg/content";
245
+
246
+ export const posts = (await glob("pages/blog/**/*.mdx")).sort((left, right) =>
247
+ String(right.meta.date || "").localeCompare(String(left.meta.date || "")),
248
+ );
249
+ ```
250
+
251
+ Use the direct package export in non-Vite server-side contexts such as `config.ts` or custom plugins:
252
+
253
+ ```ts
254
+ import { glob } from "defuss-ssg";
255
+
256
+ const posts = await glob("pages/blog/**/*.mdx", {
257
+ cwd: process.cwd(),
258
+ });
259
+ ```
260
+
261
+ Each entry contains:
262
+
263
+ - `filePath`: absolute file path
264
+ - `relativePath`: path relative to `cwd`
265
+ - `slug`: route-like identifier without a leading slash
266
+ - `route`: public route when the file lives under the configured `pages` directory
267
+ - `meta`: parsed YAML or TOML frontmatter
268
+
269
+ Notes:
270
+
271
+ - `cwd` defaults to the current working directory for the direct helper.
272
+ - The virtual module binds `cwd` and `pages` to the active SSG project automatically.
273
+ - `route` is only derived for files inside the configured `pages` directory.
274
+ - Returns metadata records only; it does not eagerly execute every matched MDX module.
275
+
140
276
  ## Endpoints
141
277
 
142
278
  Endpoint source files live under `pages/` and export HTTP method handlers.
@@ -195,9 +331,19 @@ When RPC is active, `defuss-ssg` exposes:
195
331
  - `POST /rpc`
196
332
  - `POST /rpc/schema`
197
333
 
198
- Set `rpc: false` in `config.ts` to disable RPC discovery.
334
+ Set `rpc: false` in `config.ts` to disable RPC auto-discovery.
335
+
336
+ To use the RPC in your client components, import the generated client helper:
337
+
338
+ ```ts
339
+ import { createRpcClient } from "defuss-ssg/rpc";
340
+
341
+ const rpc = createRpcClient();
342
+ const sum = await rpc.mathApi.add(2, 3);
343
+ console.log(sum); // 5
344
+ ```
199
345
 
200
- ## Plugins
346
+ ## Custom MDX plugins
201
347
 
202
348
  `defuss-ssg` plugins run in build order and can modify the pipeline at distinct phases.
203
349
 
@@ -275,7 +421,7 @@ Most projects only need the main package export.
275
421
  ## CLI Reference
276
422
 
277
423
  ```bash
278
- defuss-ssg [dev|build|serve] [folder] [--debug] [--multicore]
424
+ defuss-ssg [dev|build|serve|container-dev|container-build|container-serve] [folder] [options]
279
425
 
280
426
  No args -> dev .
281
427
  Single path -> dev <path>
@@ -290,11 +436,18 @@ Commands:
290
436
  - `dev`: starts the Vite dev server on port `3000` by default
291
437
  - `build`: generates the static site into `dist/`
292
438
  - `serve`: serves the built output from `dist/`
439
+ - `container-dev`: builds the generated image, mounts the project, and starts `dev` inside Docker or Podman
440
+ - `container-build`: builds the generated image, mounts the project, and runs `build` inside Docker or Podman
441
+ - `container-serve`: builds the generated image, mounts the project, and runs `serve` inside Docker or Podman
293
442
 
294
443
  Flags:
295
444
 
296
445
  - `--debug` or `-d`: enable verbose logging
297
446
  - `--multicore`: use `workers: "auto"` for `serve`
447
+ - `--host` or `-H <host>`: override the dev or serve bind host
448
+ - `--port` or `-p <port>`: override the dev or serve port
449
+ - `--skip-setup` or `--no-setup`: skip project dependency installation for prepared environments and containers
450
+ - `--container-args <args...>`: forward everything after the marker to the outer `docker run` or `podman run` invocation used by `docker-*`
298
451
 
299
452
  ## Local Package Development
300
453