Skip to content

Commit c345fcb

Browse files
committed
refactor: simplify next.config.mjs and enhance content directory resolution
1 parent 5a60877 commit c345fcb

5 files changed

Lines changed: 37 additions & 27 deletions

File tree

‎next.config.mjs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Dynamic Import Proxy for Vercel
2+
// This allows Vercel to see a valid Next.js config in the root
3+
// while the actual logic lives in packages/site
4+
5+
import siteConfig from './packages/site/next.config.mjs';
6+
7+
// We need to re-export the default export from the site config
8+
// Note: Depending on how site/next.config.mjs exports, this might need adjustment.
9+
// If site config exports a function (like withMDX(config)), it's an object/function.
10+
11+
export default siteConfig;

‎packages/site/next.config.mjs‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
import { createMDX } from 'fumadocs-mdx/next';
2-
import fs from 'node:fs';
3-
import path from 'node:path';
42

53
const withMDX = createMDX();
64

7-
function getBuildConfig() {
8-
try {
9-
const configPath = path.resolve(process.cwd(), '../../objectdocs.json');
10-
if (fs.existsSync(configPath)) {
11-
const content = fs.readFileSync(configPath, 'utf-8');
12-
const config = JSON.parse(content);
13-
return config.build || {};
14-
}
15-
} catch (e) {
16-
console.error('Error loading objectdocs.json in next.config.mjs:', e);
17-
}
18-
return {};
19-
}
20-
21-
const buildConfig = getBuildConfig();
22-
const isStaticExport = buildConfig.output === 'export';
23-
245
/** @type {import('next').NextConfig} */
256
const nextConfig = {
267
reactStrictMode: true,
27-
output: isStaticExport ? 'export' : undefined,
28-
images: {
29-
unoptimized: true,
30-
},
8+
distDir: '.next',
9+
images: { unoptimized: true },
3110
};
3211

3312
export default withMDX(nextConfig);

‎packages/site/source.config.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';
22
import { siteConfig } from './lib/site-config';
3+
import path from 'node:path';
4+
import fs from 'node:fs';
35

4-
const docsDir = process.env.DOCS_DIR || 'content/docs';
5-
const docsZhDir = process.env.DOCS_ZH_DIR || 'content/docs-zh-CN';
6+
function resolveContentDir(dir: string) {
7+
if (process.env.DOCS_DIR && dir === 'content/docs') return process.env.DOCS_DIR;
8+
if (process.env.DOCS_ZH_DIR && dir === 'content/docs-zh-CN') return process.env.DOCS_ZH_DIR;
9+
10+
// Try local first (Root deployment)
11+
if (fs.existsSync(path.resolve(dir))) return dir;
12+
13+
// Try parent (Monorepo/Vercel deployment where CWD is packages/site)
14+
const parentDir = path.join('../..', dir);
15+
if (fs.existsSync(path.resolve(parentDir))) return parentDir;
16+
17+
return dir;
18+
}
19+
20+
const docsDir = resolveContentDir('content/docs');
21+
const docsZhDir = resolveContentDir('content/docs-zh-CN');
622

723
export const { docs, meta } = defineDocs({
824
dir: docsDir,

‎packages/site/tsconfig.json‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@
3333
"**/*.ts",
3434
"**/*.tsx",
3535
".next/types/**/*.ts",
36-
".next/dev/types/**/*.ts"
36+
".next/dev/types/**/*.ts",
37+
"../../.next/types/**/*.ts",
38+
"../../.next/dev/types/**/*.ts"
3739
],
3840
"exclude": [
39-
"node_modules"
41+
"node_modules",
42+
"../../.next"
4043
]
4144
}

‎vercel.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"framework": "nextjs",
23
"redirects": [
34
{
45
"source": "/",

0 commit comments

Comments
 (0)