9router/next.config.mjs
local beb4599090 Fix Cowork model selection and Windows CLI packaging (#1129)
Cherry-picked from upstream PR #1129 + local improvements:
- dedupe inline remove-model handler -> use handleRemoveModel
- add .next-cli-build/ and cli/.build-home/ to .gitignore
2026-05-15 09:31:34 +07:00

66 lines
1.7 KiB
JavaScript

import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
const projectRoot = dirname(fileURLToPath(import.meta.url));
// CLI bundling needs workspace root so tracing includes hoisted node_modules (slim ~50MB).
// Docker / default uses projectRoot so server.js lands at /app/server.js (not nested).
const tracingRoot = process.env.NEXT_TRACING_ROOT_MODE === "workspace"
? join(projectRoot, "..")
: projectRoot;
/** @type {import('next').NextConfig} */
const nextConfig = {
distDir: process.env.NEXT_DIST_DIR || ".next",
output: "standalone",
serverExternalPackages: ["better-sqlite3", "sql.js", "node:sqlite", "bun:sqlite"],
turbopack: {
root: tracingRoot
},
outputFileTracingRoot: tracingRoot,
outputFileTracingExcludes: {
"*": ["./gitbook/**/*"]
},
images: {
unoptimized: true
},
env: {},
webpack: (config, { isServer }) => {
// Ignore fs/path modules in browser bundle
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
path: false,
};
}
// Exclude logs, .next, gitbook subapp from watcher
config.watchOptions = { ...config.watchOptions, ignored: /[\\/](logs|\.next|gitbook|cli)[\\/]/ };
return config;
},
async rewrites() {
return [
{
source: "/v1/v1/:path*",
destination: "/api/v1/:path*"
},
{
source: "/v1/v1",
destination: "/api/v1"
},
{
source: "/codex/:path*",
destination: "/api/v1/responses"
},
{
source: "/v1/:path*",
destination: "/api/v1/:path*"
},
{
source: "/v1",
destination: "/api/v1"
}
];
}
};
export default nextConfig;