defuss-ssg 0.3.1 → 0.5.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 +71 -22
- package/dist/cli.mjs +51 -25
- package/dist/index.cjs +163 -1404
- package/dist/index.d.cts +46 -22
- package/dist/index.d.mts +46 -22
- package/dist/index.mjs +12 -11
- package/dist/runtime.cjs +640 -72
- package/dist/runtime.d.cts +17 -3
- package/dist/runtime.d.mts +17 -3
- package/dist/runtime.mjs +638 -70
- package/dist/serve-BJ00mBAJ.mjs +160 -0
- package/dist/vite-B4oPT39d.mjs +1804 -0
- package/dist/vite-CMGAfJFW.d.cts +7913 -0
- package/dist/vite-CMGAfJFW.d.mts +7913 -0
- package/dist/vite-DySvB3OP.cjs +1829 -0
- package/dist/vite.cjs +27 -0
- package/dist/vite.d.cts +4 -0
- package/dist/vite.d.mts +4 -0
- package/dist/vite.mjs +21 -0
- package/package.json +21 -31
- package/dist/components/index.cjs +0 -29
- package/dist/components/index.d.cts +0 -11
- package/dist/components/index.d.mts +0 -11
- package/dist/components/index.mjs +0 -27
- package/dist/plugins/index.cjs +0 -8
- package/dist/plugins/index.d.cts +0 -7
- package/dist/plugins/index.d.mts +0 -7
- package/dist/plugins/index.mjs +0 -2
- package/dist/serve-C7GCBFVo.mjs +0 -1419
- package/dist/tailwind-C4AuHybm.cjs +0 -14
- package/dist/tailwind-DV23JSh-.mjs +0 -12
- package/dist/types-CDQPtj1-.d.cts +0 -125
- package/dist/types-CDQPtj1-.d.mts +0 -125
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ bunx defuss-ssg build ./folder
|
|
|
29
29
|
Or install globally or locally in a project:
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
|
|
32
|
+
bun add -g defuss-ssg
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
And then run (in an NPM script or globally):
|
|
@@ -40,13 +40,13 @@ And then run (in an NPM script or globally):
|
|
|
40
40
|
defuss-ssg build ./folder
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
<h4>
|
|
43
|
+
<h4>Vite-powered development</h4>
|
|
44
44
|
|
|
45
45
|
```bash
|
|
46
|
-
defuss-ssg
|
|
46
|
+
defuss-ssg dev ./folder
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
This starts a
|
|
49
|
+
This starts a Vite dev server at http://localhost:3000 and watches for changes in:
|
|
50
50
|
|
|
51
51
|
- `pages/` directory
|
|
52
52
|
- `components/` directory
|
|
@@ -54,6 +54,16 @@ This starts a local server at http://localhost:3000 and watches for changes in:
|
|
|
54
54
|
|
|
55
55
|
Changes trigger automatic rebuilds, with the last change always taking priority to prevent build queueing issues.
|
|
56
56
|
|
|
57
|
+
The current migration bridge still writes dev output to `dist/` while the request-time Vite renderer is being moved over.
|
|
58
|
+
|
|
59
|
+
<h4>Production serving</h4>
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
defuss-ssg serve ./folder
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This serves already-built output with `defuss-express`. Run `defuss-ssg build ./folder` first.
|
|
66
|
+
|
|
57
67
|
<h4>Local development of SSG and running the example</h4>
|
|
58
68
|
|
|
59
69
|
Unlike other SSG systems, this package is **not** meant to be installed in a project, but rather used as a global CLI tool or programmatically.
|
|
@@ -61,14 +71,14 @@ Unlike other SSG systems, this package is **not** meant to be installed in a pro
|
|
|
61
71
|
Developing this means to clone the repo, install dependencies and run the example site:
|
|
62
72
|
|
|
63
73
|
```bash
|
|
64
|
-
git clone
|
|
74
|
+
git clone https://github.com/kyr0/defuss.git
|
|
65
75
|
|
|
66
76
|
cd defuss/packages/ssg
|
|
67
77
|
|
|
68
78
|
bun i && bun build
|
|
69
79
|
|
|
70
80
|
# for building and serving the example site with auto-rebuild:
|
|
71
|
-
bun run cli-
|
|
81
|
+
bun run cli-dev ./example
|
|
72
82
|
|
|
73
83
|
# for one-time build of the example site:
|
|
74
84
|
bun run cli-build ./example
|
|
@@ -81,7 +91,7 @@ Please create a PR or issue if you find any bugs or have feature requests.
|
|
|
81
91
|
Advanced users may want to use the library programmatically:
|
|
82
92
|
|
|
83
93
|
```typescript
|
|
84
|
-
import { setup, build, serve } from "defuss-ssg";
|
|
94
|
+
import { setup, build, dev, serve } from "defuss-ssg";
|
|
85
95
|
|
|
86
96
|
(async () => {
|
|
87
97
|
|
|
@@ -98,11 +108,17 @@ import { setup, build, serve } from "defuss-ssg";
|
|
|
98
108
|
debug: true,
|
|
99
109
|
});
|
|
100
110
|
|
|
101
|
-
// Or
|
|
102
|
-
await
|
|
111
|
+
// Or start the Vite-backed dev server
|
|
112
|
+
await dev({
|
|
103
113
|
projectDir: "./my-site",
|
|
104
114
|
debug: true,
|
|
105
115
|
});
|
|
116
|
+
|
|
117
|
+
// Or serve an already-built production output
|
|
118
|
+
await serve({
|
|
119
|
+
projectDir: "./my-site",
|
|
120
|
+
workers: "auto",
|
|
121
|
+
});
|
|
106
122
|
})();
|
|
107
123
|
```
|
|
108
124
|
|
|
@@ -112,7 +128,7 @@ Overview
|
|
|
112
128
|
|
|
113
129
|
> `defuss-ssg` is a CLI tool and library for building static websites using modern JavaScript/TypeScript and `defuss`. It reads content files (Markdown, MDX) from a specified directory, processes them with MDX plugins, compiles components with esbuild, and outputs fully static HTML sites ready for deployment.
|
|
114
130
|
|
|
115
|
-
> It supports a plugin system for extending the build process at various phases (pre-build, post-build, page-level transformations),
|
|
131
|
+
> It supports a plugin system for extending the build process at various phases (pre-build, post-build, page-level transformations), Vite-backed development, and defuss-express production serving.
|
|
116
132
|
|
|
117
133
|
<h3 align="center">
|
|
118
134
|
|
|
@@ -123,8 +139,9 @@ Features
|
|
|
123
139
|
- **MDX Support**: Full Markdown + JSX support with frontmatter parsing
|
|
124
140
|
- **Component Integration**: Use defuss components in your MDX files
|
|
125
141
|
- **Plugin System**: Extend the build process with custom plugins at multiple phases
|
|
126
|
-
- **Fast Compilation**: Powered by esbuild
|
|
127
|
-
- **
|
|
142
|
+
- **Fast Compilation**: Powered by esbuild today, with Vite now orchestrating development
|
|
143
|
+
- **Dev Mode**: Vite-backed development server with auto-rebuild and full reload
|
|
144
|
+
- **Production Runtime**: `defuss-express` serves static output plus dynamic endpoints and RPC
|
|
128
145
|
- **TypeScript Ready**: Full TypeScript support for components and configuration
|
|
129
146
|
- **Asset Handling**: Automatic copying of static assets to output directory
|
|
130
147
|
- **Flexible Configuration**: Configurable via TypeScript config file with sensible defaults
|
|
@@ -139,15 +156,15 @@ Create a project structure like this:
|
|
|
139
156
|
|
|
140
157
|
```typescript
|
|
141
158
|
my-site/
|
|
142
|
-
|
|
143
|
-
│
|
|
144
|
-
│
|
|
145
|
-
│
|
|
146
|
-
|
|
147
|
-
│
|
|
148
|
-
|
|
149
|
-
│
|
|
150
|
-
|
|
159
|
+
├-- pages/
|
|
160
|
+
│ ├-- index.mdx
|
|
161
|
+
│ └-- blog/
|
|
162
|
+
│ └-- hello-world.mdx
|
|
163
|
+
├-- components/
|
|
164
|
+
│ └-- button.tsx
|
|
165
|
+
├-- assets/
|
|
166
|
+
│ └-- styles.css
|
|
167
|
+
└-- config.ts
|
|
151
168
|
```
|
|
152
169
|
Then run `defuss-ssg build ./my-site` and a `dist` folder will be created with the complete static build.
|
|
153
170
|
|
|
@@ -310,6 +327,38 @@ Commands:
|
|
|
310
327
|
serve <folder> Serve with auto-rebuild on changes
|
|
311
328
|
```
|
|
312
329
|
|
|
330
|
+
<h3 align="center">
|
|
331
|
+
Benchmark
|
|
332
|
+
</h3>
|
|
333
|
+
|
|
334
|
+
The following benchmark was performed on the RPC endpoint of the example site, which calls a simple server-side function that adds two numbers. The test was run with 1024 concurrent connections, a pipelining factor of 256, and 8 workers for 30 seconds on a Macbook Air M4, 24 GB RAM under medium load (IDE, browser, docker, Spotify, Mail and terminal running while the benchmark was conducted).
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
$ bun x autocannon -p 256 -w 8 -c 1024 -d 30 -m POST -H 'content-type: application/json' -b '{"className":"mathApi","methodName":"add","args":[1,2]}' http://127.0.0.1:3000/rpc
|
|
338
|
+
Running 30s test @ http://127.0.0.1:3000/rpc
|
|
339
|
+
1024 connections with 256 pipelining factor
|
|
340
|
+
8 workers
|
|
341
|
+
|
|
342
|
+
/
|
|
343
|
+
┌─────────┬────────┬─────────┬─────────┬─────────┬────────────┬────────────┬─────────┐
|
|
344
|
+
│ Stat │ 2.5% │ 50% │ 97.5% │ 99% │ Avg │ Stdev │ Max │
|
|
345
|
+
├─────────┼────────┼─────────┼─────────┼─────────┼────────────┼────────────┼─────────┤
|
|
346
|
+
│ Latency │ 617 ms │ 4708 ms │ 5629 ms │ 6230 ms │ 4367.37 ms │ 1263.71 ms │ 7115 ms │
|
|
347
|
+
└─────────┴────────┴─────────┴─────────┴─────────┴────────────┴────────────┴─────────┘
|
|
348
|
+
┌───────────┬─────────┬─────────┬─────────┬─────────┬──────────┬─────────┬─────────┐
|
|
349
|
+
│ Stat │ 1% │ 2.5% │ 50% │ 97.5% │ Avg │ Stdev │ Min │
|
|
350
|
+
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼─────────┼─────────┤
|
|
351
|
+
│ Req/Sec │ 41,215 │ 41,215 │ 54,559 │ 66,751 │ 55,371.2 │ 5,492.3 │ 41,210 │
|
|
352
|
+
├───────────┼─────────┼─────────┼─────────┼─────────┼──────────┼─────────┼─────────┤
|
|
353
|
+
│ Bytes/Sec │ 8.37 MB │ 8.37 MB │ 11.1 MB │ 13.5 MB │ 11.2 MB │ 1.11 MB │ 8.37 MB │
|
|
354
|
+
└───────────┴─────────┴─────────┴─────────┴─────────┴──────────┴─────────┴─────────┘
|
|
355
|
+
|
|
356
|
+
Req/Bytes counts sampled once per second.
|
|
357
|
+
# of samples: 240
|
|
358
|
+
|
|
359
|
+
1923k requests in 30.08s, 337 MB read
|
|
360
|
+
```
|
|
361
|
+
|
|
313
362
|
<p align="center">
|
|
314
363
|
|
|
315
364
|
<img src="https://raw.githubusercontent.com/kyr0/defuss/refs/heads/main/assets/defuss_comic.png" width="400px" />
|
|
@@ -318,4 +367,4 @@ Commands:
|
|
|
318
367
|
|
|
319
368
|
<p align="center">
|
|
320
369
|
<i><b>Come visit us on <code>defuss</code> Island!</b></i>
|
|
321
|
-
</p>
|
|
370
|
+
</p>
|
package/dist/cli.mjs
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { v as validateProjectDir, b as build
|
|
2
|
+
import { v as validateProjectDir, b as build } from './vite-B4oPT39d.mjs';
|
|
3
|
+
import { d as dev, s as serve } from './serve-BJ00mBAJ.mjs';
|
|
3
4
|
import { join, dirname, resolve } from 'node:path';
|
|
4
5
|
import { existsSync, readFileSync } from 'node:fs';
|
|
5
6
|
import { spawn } from 'node:child_process';
|
|
6
|
-
import 'node:os';
|
|
7
|
-
import 'chokidar';
|
|
8
|
-
import 'elysia';
|
|
9
|
-
import '@elysiajs/static';
|
|
10
7
|
import 'node:fs/promises';
|
|
8
|
+
import 'node:url';
|
|
9
|
+
import 'defuss/server';
|
|
10
|
+
import 'node:crypto';
|
|
11
|
+
import '@mdx-js/rollup';
|
|
12
|
+
import 'fast-glob';
|
|
13
|
+
import 'vite';
|
|
14
|
+
import 'defuss-vite';
|
|
15
|
+
import 'node:os';
|
|
11
16
|
import 'esbuild';
|
|
12
17
|
import 'rehype-katex';
|
|
13
18
|
import 'rehype-stringify';
|
|
@@ -17,11 +22,7 @@ import 'remark-gfm';
|
|
|
17
22
|
import 'remark-parse';
|
|
18
23
|
import 'remark-rehype';
|
|
19
24
|
import 'remark-mdx-frontmatter';
|
|
20
|
-
import '
|
|
21
|
-
import '@mdx-js/esbuild';
|
|
22
|
-
import 'fast-glob';
|
|
23
|
-
import 'defuss/server';
|
|
24
|
-
import 'node:url';
|
|
25
|
+
import 'defuss-express';
|
|
25
26
|
|
|
26
27
|
const canResolve = (dep, dir) => {
|
|
27
28
|
let current = dir;
|
|
@@ -68,7 +69,12 @@ const runInstall = (cmd, args, cwd, env) => new Promise((resolve, reject) => {
|
|
|
68
69
|
child.on("error", reject);
|
|
69
70
|
child.on("close", (code) => {
|
|
70
71
|
if (code === 0) resolve();
|
|
71
|
-
else
|
|
72
|
+
else
|
|
73
|
+
reject(
|
|
74
|
+
new Error(
|
|
75
|
+
`${cmd} ${args.join(" ")} exited with code ${code ?? "unknown"}`
|
|
76
|
+
)
|
|
77
|
+
);
|
|
72
78
|
});
|
|
73
79
|
});
|
|
74
80
|
const setup = async (projectDir) => {
|
|
@@ -109,9 +115,7 @@ const setup = async (projectDir) => {
|
|
|
109
115
|
);
|
|
110
116
|
const allResolvable = depNames.length === 0 || depNames.every((d) => canResolve(d, projectDir));
|
|
111
117
|
if (allResolvable) {
|
|
112
|
-
console.log(
|
|
113
|
-
`All dependencies already available \u2014 skipping install.`
|
|
114
|
-
);
|
|
118
|
+
console.log(`All dependencies already available - skipping install.`);
|
|
115
119
|
return { code: "OK", message: "Setup completed (deps already available)" };
|
|
116
120
|
}
|
|
117
121
|
console.log(`Setting up project in ${projectDir} using ${pm}...`);
|
|
@@ -151,13 +155,13 @@ Falling back to npm install...`
|
|
|
151
155
|
} catch (npmError) {
|
|
152
156
|
console.warn(
|
|
153
157
|
`Warning: npm install also failed: ${npmError.message}
|
|
154
|
-
Continuing anyway
|
|
158
|
+
Continuing anyway - dependencies may already be available.`
|
|
155
159
|
);
|
|
156
160
|
}
|
|
157
161
|
} else {
|
|
158
162
|
console.warn(
|
|
159
163
|
`Warning: ${error.message}
|
|
160
|
-
Continuing anyway
|
|
164
|
+
Continuing anyway - dependencies may already be available.`
|
|
161
165
|
);
|
|
162
166
|
}
|
|
163
167
|
}
|
|
@@ -169,16 +173,38 @@ Continuing anyway \u2014 dependencies may already be available.`
|
|
|
169
173
|
const debug = args.includes("--debug") || args.includes("-d");
|
|
170
174
|
const multicore = args.includes("--multicore");
|
|
171
175
|
const positional = args.filter((a) => !a.startsWith("-"));
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
const usage = "Usage: defuss-ssg [dev|build|serve] [folder]\n No args \u2192 serve .\n Single path \u2192 serve <path>\n Single command \u2192 <command> .\n Command + folder \u2192 <command> <folder>\n Flags: [--debug] [--multicore]";
|
|
177
|
+
let command;
|
|
178
|
+
let folder;
|
|
179
|
+
if (positional.length === 0) {
|
|
180
|
+
command = "serve";
|
|
181
|
+
folder = ".";
|
|
182
|
+
} else if (positional.length === 1) {
|
|
183
|
+
const arg = positional[0];
|
|
184
|
+
if (arg === "dev" || arg === "build" || arg === "serve") {
|
|
185
|
+
command = arg;
|
|
186
|
+
folder = ".";
|
|
187
|
+
} else if (arg.startsWith(".") || arg.startsWith("/")) {
|
|
188
|
+
command = "serve";
|
|
189
|
+
folder = arg;
|
|
190
|
+
} else {
|
|
191
|
+
console.error(usage);
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
194
|
+
} else {
|
|
195
|
+
command = positional[0];
|
|
196
|
+
folder = positional[1];
|
|
178
197
|
}
|
|
179
198
|
const projectDir = resolve(folder);
|
|
180
199
|
await setup(projectDir);
|
|
181
|
-
if (command === "
|
|
200
|
+
if (command === "dev") {
|
|
201
|
+
console.log(`Starting Vite dev server for ${folder}...`);
|
|
202
|
+
await dev({
|
|
203
|
+
projectDir,
|
|
204
|
+
debug,
|
|
205
|
+
writeDevOutput: true
|
|
206
|
+
});
|
|
207
|
+
} else if (command === "build") {
|
|
182
208
|
console.log(`Building ${folder}...`);
|
|
183
209
|
await build({
|
|
184
210
|
projectDir,
|
|
@@ -186,11 +212,11 @@ Continuing anyway \u2014 dependencies may already be available.`
|
|
|
186
212
|
mode: "build"
|
|
187
213
|
});
|
|
188
214
|
} else if (command === "serve") {
|
|
189
|
-
console.log(`Serving ${folder}...`);
|
|
215
|
+
console.log(`Serving built output for ${folder}...`);
|
|
190
216
|
await serve({
|
|
191
217
|
projectDir,
|
|
192
218
|
debug,
|
|
193
|
-
multicore
|
|
219
|
+
workers: multicore ? "auto" : 1
|
|
194
220
|
});
|
|
195
221
|
} else {
|
|
196
222
|
console.error(usage);
|