@bractjs/bractjs 0.1.20 → 0.1.21
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/bin/cli.ts +10 -1
- package/package.json +1 -1
- package/src/build/bundler.ts +1 -1
- package/src/config/load.ts +17 -0
- package/src/dev/rebuilder.ts +1 -1
- package/src/dev/server.ts +7 -4
- package/src/server/serve.ts +2 -0
- package/types/config.d.ts +4 -0
package/bin/cli.ts
CHANGED
|
@@ -75,7 +75,16 @@ switch (command) {
|
|
|
75
75
|
// server build (react-dom/server.bun production) instead of the dev one.
|
|
76
76
|
if (!process.env.NODE_ENV) process.env.NODE_ENV = "production";
|
|
77
77
|
const { runBuild } = await import("../src/build/bundler.ts");
|
|
78
|
-
|
|
78
|
+
const { loadUserConfig } = await import("../src/config/load.ts");
|
|
79
|
+
const userCfg = await loadUserConfig();
|
|
80
|
+
await runBuild({
|
|
81
|
+
port: 3000,
|
|
82
|
+
appDir: "./app",
|
|
83
|
+
publicDir: "./public",
|
|
84
|
+
buildDir: "./build",
|
|
85
|
+
manifest: { clientEntry: "", routes: {} },
|
|
86
|
+
...userCfg,
|
|
87
|
+
});
|
|
79
88
|
break;
|
|
80
89
|
}
|
|
81
90
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bractjs/bractjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "Production-grade SSR framework for Bun + React 19. File-based routing, streaming SSR, server actions, typed routes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/bractjs/bractjs#readme",
|
package/src/build/bundler.ts
CHANGED
|
@@ -54,7 +54,7 @@ export async function runBuild(config: BractJSConfig): Promise<void> {
|
|
|
54
54
|
minify: config.minify ?? true,
|
|
55
55
|
sourcemap: config.sourcemap ?? "external",
|
|
56
56
|
define: buildDefines(config),
|
|
57
|
-
plugins: [serverOnlyPlugin, useServerProxyPlugin, clientEnvPlugin(config.clientEnv ?? [], Bun.env as Record<string, string>), cssModulesPlugin],
|
|
57
|
+
plugins: [serverOnlyPlugin, useServerProxyPlugin, clientEnvPlugin(config.clientEnv ?? [], Bun.env as Record<string, string>), cssModulesPlugin, ...(config.plugins ?? [])],
|
|
58
58
|
});
|
|
59
59
|
if (!clientResult.success) throw new AggregateError(clientResult.logs, "Client build failed");
|
|
60
60
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import type { BractJSConfig } from "../server/serve.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Load `bractjs.config.ts` (or `.js`) from the user's cwd if present.
|
|
6
|
+
* Returns an empty object when no file exists — callers fall back to defaults.
|
|
7
|
+
*/
|
|
8
|
+
export async function loadUserConfig(): Promise<Partial<BractJSConfig>> {
|
|
9
|
+
for (const name of ["bractjs.config.ts", "bractjs.config.js"]) {
|
|
10
|
+
const path = resolve(process.cwd(), name);
|
|
11
|
+
if (!(await Bun.file(path).exists())) continue;
|
|
12
|
+
const mod = await import(path);
|
|
13
|
+
const cfg = (mod.default ?? mod) as Partial<BractJSConfig>;
|
|
14
|
+
return cfg ?? {};
|
|
15
|
+
}
|
|
16
|
+
return {};
|
|
17
|
+
}
|
package/src/dev/rebuilder.ts
CHANGED
|
@@ -48,7 +48,7 @@ export async function rebuildClient(
|
|
|
48
48
|
// structure. publicPath + ../ traversals produce wrong absolute URLs.
|
|
49
49
|
minify: false,
|
|
50
50
|
sourcemap: "inline",
|
|
51
|
-
plugins: [useServerProxyPlugin],
|
|
51
|
+
plugins: [useServerProxyPlugin, ...(config?.plugins ?? [])],
|
|
52
52
|
});
|
|
53
53
|
} finally {
|
|
54
54
|
await rm(shimPath, { force: true });
|
package/src/dev/server.ts
CHANGED
|
@@ -6,15 +6,18 @@ import { rebuildClient } from "./rebuilder.ts";
|
|
|
6
6
|
import { filePathToPattern } from "../server/scanner.ts";
|
|
7
7
|
import { basename, extname } from "node:path";
|
|
8
8
|
import type { LifecycleHooks } from "../server/lifecycle.ts";
|
|
9
|
+
import { loadUserConfig } from "../config/load.ts";
|
|
9
10
|
|
|
10
11
|
// Must precede any user-code import so SSR-time isDevRuntime() checks
|
|
11
12
|
// (e.g. inside <LiveReload>) observe the dev mode.
|
|
12
13
|
setRuntimeMode("dev");
|
|
13
14
|
|
|
15
|
+
const userConfig = await loadUserConfig();
|
|
16
|
+
|
|
14
17
|
const hmr = createHmrServer(3001);
|
|
15
18
|
|
|
16
19
|
// Build client bundle before the HTTP server starts accepting requests
|
|
17
|
-
const { duration: initialMs } = await rebuildClient();
|
|
20
|
+
const { duration: initialMs } = await rebuildClient(userConfig);
|
|
18
21
|
console.log(`[bractjs] initial client build in ${initialMs}ms`);
|
|
19
22
|
|
|
20
23
|
// Load user lifecycle hooks if defined (e.g. app/lifecycle.ts)
|
|
@@ -27,10 +30,10 @@ try {
|
|
|
27
30
|
// No lifecycle file — that's fine
|
|
28
31
|
}
|
|
29
32
|
|
|
30
|
-
createServer({ port: 3000, ...lifecycle });
|
|
33
|
+
createServer({ port: 3000, ...userConfig, ...lifecycle });
|
|
31
34
|
|
|
32
|
-
watchApp("./app", async (file) => {
|
|
33
|
-
const { duration } = await rebuildClient();
|
|
35
|
+
watchApp(userConfig.appDir ?? "./app", async (file) => {
|
|
36
|
+
const { duration } = await rebuildClient(userConfig);
|
|
34
37
|
|
|
35
38
|
// Route files (not layout): do a fine-grained module swap without full reload.
|
|
36
39
|
// Root, layouts, and other files: fall back to full page reload.
|
package/src/server/serve.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface BractJSConfig {
|
|
|
29
29
|
sourcemap?: "none" | "linked" | "inline" | "external";
|
|
30
30
|
minify?: boolean;
|
|
31
31
|
clientEnv?: string[];
|
|
32
|
+
/** User Bun bundler plugins appended to the client build (e.g. bun-plugin-tailwind). */
|
|
33
|
+
plugins?: import("bun").BunPlugin[];
|
|
32
34
|
buildDir?: string;
|
|
33
35
|
/** Directory for transformed image cache. Defaults to .bract-image-cache */
|
|
34
36
|
imageCacheDir?: string;
|
package/types/config.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { BunPlugin } from "bun";
|
|
2
|
+
|
|
1
3
|
export interface BractJSConfig {
|
|
2
4
|
/** TCP port to listen on. Default: 3000. */
|
|
3
5
|
port: number;
|
|
@@ -15,6 +17,8 @@ export interface BractJSConfig {
|
|
|
15
17
|
minify?: boolean;
|
|
16
18
|
/** process.env keys allowed to be inlined into client bundles. */
|
|
17
19
|
clientEnv?: string[];
|
|
20
|
+
/** User Bun bundler plugins appended to the client build (e.g. bun-plugin-tailwind). */
|
|
21
|
+
plugins?: BunPlugin[];
|
|
18
22
|
/** Called once after the server starts listening. Use to open DB connections, warm caches, etc. */
|
|
19
23
|
onStart?: () => Promise<void> | void;
|
|
20
24
|
/** Called before the process exits (any signal or uncaught error). Use to close DB connections, flush queues, etc. */
|