Skip to content

Commit 60dc186

Browse files
update vercel
1 parent 14e08b6 commit 60dc186

File tree

1 file changed

+18
-38
lines changed

1 file changed

+18
-38
lines changed

next.config.mjs

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,34 @@ import { createMDX } from 'fumadocs-mdx/next';
22

33
const withMDX = createMDX();
44

5-
// 检测是否为生产构建(静态导出)
6-
const isStaticExport = process.env.NODE_ENV === 'production';
7-
85
/** @type {import('next').NextConfig} */
96
const config = {
107
reactStrictMode: true,
118
turbopack: false,
12-
13-
// 只在生产环境启用静态导出
14-
...(isStaticExport && {
15-
output: 'export',
16-
trailingSlash: true,
17-
basePath: '/hello-adp-docs',
18-
assetPrefix: '/hello-adp-docs/',
19-
}),
20-
9+
10+
// 在 Vercel 上不使用静态导出与 basePath/assetPrefix
2111
images: {
22-
unoptimized: isStaticExport, // 只在静态导出时禁用优化
12+
// 使用 Vercel 默认图片优化;保留远程图支持
2313
remotePatterns: [
24-
{
25-
protocol: 'https',
26-
hostname: '**',
27-
pathname: '**',
28-
},
29-
{
30-
protocol: 'http',
31-
hostname: '**',
32-
pathname: '**',
33-
}
14+
{ protocol: 'https', hostname: '**', pathname: '**' },
15+
{ protocol: 'http', hostname: '**', pathname: '**' },
3416
],
3517
dangerouslyAllowSVG: true,
3618
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
37-
}
19+
},
3820
};
3921

40-
// 只在非静态导出模式下添加 headers
41-
if (!isStaticExport) {
42-
config.headers = async () => [
43-
{
44-
source: '/(.*)',
45-
headers: [
46-
{
47-
key: 'Content-Security-Policy',
48-
value: "frame-ancestors 'self' *.tencentcloud.com *.hellodify.com; frame-src 'self' *.tencentcloud.com *.hellodify.com https://giscus.app https://www.youtube.com/embed/ https://*.youtube.com https://*.vercel.app; child-src 'self' *.tencentcloud.com *.hellodify.com https://giscus.app https://www.youtube.com/embed/ https://*.youtube.com https://*.vercel.app; img-src 'self' data: *.tencentcloud.com *.hellodify.com https://avatars.githubusercontent.com https://twimg.com https://pbs.twimg.com https://*.github.io https://*.youtube.com https://*.ytimg.com https://*.vercel.app; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://giscus.app https://www.googletagmanager.com https://www.google-analytics.com; connect-src 'self' https://api.github.com https://www.google-analytics.com https://www.googletagmanager.com https://analytics.google.com;"
49-
}
50-
]
51-
}
52-
];
53-
}
22+
// 在 Vercel 环境下 headers 可以生效
23+
config.headers = async () => [
24+
{
25+
source: '/(.*)',
26+
headers: [
27+
{
28+
key: 'Content-Security-Policy',
29+
value: "frame-ancestors 'self' *.tencentcloud.com *.hellodify.com; frame-src 'self' *.tencentcloud.com *.hellodify.com https://giscus.app https://www.youtube.com/embed/ https://*.youtube.com https://*.vercel.app; child-src 'self' *.tencentcloud.com *.hellodify.com https://giscus.app https://www.youtube.com/embed/ https://*.youtube.com https://*.vercel.app; img-src 'self' data: *.tencentcloud.com *.hellodify.com https://avatars.githubusercontent.com https://twimg.com https://pbs.twimg.com https://*.github.io https://*.youtube.com https://*.ytimg.com https://*.vercel.app; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://giscus.app https://www.googletagmanager.com https://www.google-analytics.com; connect-src 'self' https://api.github.com https://www.google-analytics.com https://www.googletagmanager.com https://analytics.google.com;"
30+
}
31+
]
32+
}
33+
];
5434

5535
export default withMDX(config);

0 commit comments

Comments
 (0)