-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
86 lines (74 loc) · 1.94 KB
/
next.config.js
File metadata and controls
86 lines (74 loc) · 1.94 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
/** @type {import('next').NextConfig} */
const nextConfig = {
// 启用standalone构建(用于Docker)
output: 'standalone',
// 启用流式响应
experimental: {
typedRoutes: true,
},
// 外部包配置 - 基于 urllib PR #457 的修复思路
serverExternalPackages: [
'@prisma/client',
'mysql2',
'canvas',
// 避免 vm2 安全漏洞相关的包
'vm2',
'degenerator',
'pac-resolver',
'pac-proxy-agent',
'proxy-agent'
],
// 配置图片处理
images: {
unoptimized: true, // 禁用图片优化,支持所有域名
},
// 环境变量配置
env: {
CUSTOM_KEY: process.env.CUSTOM_KEY,
},
// 构建时忽略的错误
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: true,
},
// Webpack 配置 - 基于 urllib 避免 vm2 依赖的策略
webpack: (config, { isServer }) => {
// 为所有有安全问题的模块添加 fallback
config.resolve.fallback = {
...config.resolve.fallback,
// 核心安全问题模块
'vm2': false,
'coffee-script': false,
'degenerator': false,
// 代理相关模块 (参考 urllib PR #457)
'pac-resolver': false,
'pac-proxy-agent': false,
'proxy-agent': false,
};
// 服务器端外部化这些模块
if (isServer) {
config.externals = config.externals || [];
// 添加条件外部化,只在模块存在时才外部化
const problematicModules = [
'vm2',
'coffee-script',
'degenerator',
'pac-resolver',
'pac-proxy-agent',
'proxy-agent'
];
problematicModules.forEach(module => {
config.externals.push(({ request }, callback) => {
if (request === module) {
return callback(null, `commonjs ${module}`);
}
callback();
});
});
}
return config;
}
}
module.exports = nextConfig;