forked from agegr/pi-web
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnext.config.ts
More file actions
89 lines (85 loc) · 3.24 KB
/
Copy pathnext.config.ts
File metadata and controls
89 lines (85 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { NextConfig } from "next";
import { readFileSync } from "fs";
import { join } from "path";
const { version } = JSON.parse(readFileSync(join(__dirname, "package.json"), "utf8")) as { version: string };
let ompVersion = "unknown";
try {
const ompPkgPath = join(__dirname, "node_modules/@oh-my-pi/pi-coding-agent/package.json");
ompVersion = (JSON.parse(readFileSync(ompPkgPath, "utf8")) as { version: string }).version;
} catch { /* package not found, use default */ }
/**
* The omp SDK is published as TypeScript sources and imports `bun:` builtins,
* so webpack must never try to parse it: every `@oh-my-pi/*` request stays a
* runtime import that Bun resolves itself.
*
* `serverExternalPackages` alone is not enough — it leaves the SDK's own
* transitive entry points (`@oh-my-pi/pi-ai`, `@oh-my-pi/pi-catalog/...`)
* inside the bundle — so the rule below is applied unconditionally to the
* whole scope.
*/
const OMP_SDK_REQUEST = /^@oh-my-pi\//;
const nextConfig: NextConfig = {
// Desktop builds (scripts/stage-desktop.mjs) redirect the production build
// into src-tauri/server/.next so packaging never touches the dev `.next/`.
distDir: process.env.OMP_WEB_DIST_DIR || ".next",
serverExternalPackages: [
"undici",
"@oh-my-pi/pi-coding-agent",
"@oh-my-pi/pi-agent-core",
"@oh-my-pi/pi-ai",
"@oh-my-pi/pi-catalog",
"@oh-my-pi/pi-tui",
"@oh-my-pi/pi-utils",
],
webpack: (config, { isServer, nextRuntime }) => {
if (!isServer || nextRuntime === "edge") {
// instrumentation.ts has a Node-only dynamic import guarded by
// NEXT_RUNTIME. Webpack still traces it for the browser fallback unless
// the server-only module is explicitly excluded.
config.resolve.alias["@/lib/http-dispatcher"] = false;
return config;
}
const externals = Array.isArray(config.externals) ? config.externals : [config.externals].filter(Boolean);
config.externals = [
({ request }: { request?: string }, callback: (error?: unknown, result?: string) => void) => {
// `import`, not `commonjs`: the SDK's package exports declare only an
// `import` condition, so a `require()` of it cannot resolve at all.
if (request && OMP_SDK_REQUEST.test(request)) return callback(undefined, `import ${request}`);
return callback();
},
...externals,
];
return config;
},
// Allow the dev server to be reached over the loopback interface (the
// browser tab connects to http://127.0.0.1:30141) and from LAN devices.
allowedDevOrigins: ["127.0.0.1", "192.168.*.*"],
async headers() {
return [
{
source: "/",
headers: [
{ key: "Cache-Control", value: "private, no-cache, max-age=0, must-revalidate" },
],
},
{
source: "/sw.js",
headers: [
{ key: "Cache-Control", value: "public, max-age=0, must-revalidate" },
{ key: "Service-Worker-Allowed", value: "/" },
],
},
{
source: "/manifest.webmanifest",
headers: [
{ key: "Cache-Control", value: "public, max-age=0, must-revalidate" },
],
},
];
},
env: {
NEXT_PUBLIC_APP_VERSION: version,
NEXT_PUBLIC_OMP_VERSION: ompVersion,
},
};
export default nextConfig;