-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathnext.config.ts
More file actions
195 lines (186 loc) · 5.21 KB
/
Copy pathnext.config.ts
File metadata and controls
195 lines (186 loc) · 5.21 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import type { NextConfig } from "next";
const isAnalyzeEnabled = process.env.ANALYZE === "true";
const isDev = process.env.NODE_ENV === "development";
const isProd = process.env.NODE_ENV === "production";
// `BuildStatsPlugin` writes a JSON payload into `.next/` for on-demand
// inspection. It is ONLY meant for local development/debugging — production
// builds must never emit it.
// - Gate on the explicit `ANALYZE=true` opt-in flag.
// - Hard-disable on production builds even if `ANALYZE=true` is set
// (e.g. misconfigured CI).
// - Skip on server builds (this plugin is client-side only).
// See README § "Build stats plugin" for details.
const csp = [
"default-src 'self'",
`script-src 'self'${isDev ? " 'unsafe-eval'" : ""}`,
"style-src 'self'",
"img-src 'self' data: blob: https:",
"font-src 'self' data: https:",
isDev
? "connect-src 'self' https: wss: ws: http:"
: "connect-src 'self' https: wss:",
"media-src 'self' data: blob: https:",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
"frame-ancestors 'none'",
"worker-src 'self' blob:",
"manifest-src 'self'",
"report-uri /api/csp-report",
...(isDev ? [] : ["upgrade-insecure-requests"]),
].join("; ");
const nextConfig: NextConfig = {
output: "standalone",
typescript: {
ignoreBuildErrors: true,
},
experimental: {
optimizePackageImports: [
"lucide-react",
"recharts",
"framer-motion",
"wagmi",
"viem",
],
},
images: {
remotePatterns: [
{
protocol: "https",
hostname: "images.unsplash.com",
},
],
formats: ["image/avif", "image/webp"],
},
turbopack: {},
async headers() {
return [
{
source: "/_next/static/:path*",
headers: [
{
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
},
],
},
{
source: "/:path*.(png|jpg|jpeg|gif|webp|avif|svg|ico)",
headers: [
{
key: "Cache-Control",
value: "public, max-age=604800, stale-while-revalidate=86400",
},
],
},
{
source: "/sw.js",
headers: [
{
key: "Cache-Control",
value: "no-cache, no-store, must-revalidate",
},
],
},
{
source: "/properties/:path*",
headers: [
{
key: "Cache-Control",
value:
"public, max-age=60, stale-while-revalidate=300, s-maxage=300",
},
{
key: "Vary",
value: "Accept-Encoding",
},
],
},
{
source: "/api/:path*",
headers: [
{
key: "Cache-Control",
value: "no-cache, no-store, must-revalidate",
},
],
},
{
source: "/:path*",
headers: [
{
key: "Content-Security-Policy",
value: csp,
},
],
},
];
},
webpack: (config, { isServer, webpack }) => {
config.resolve = config.resolve ?? {};
config.resolve.alias = {
...(config.resolve.alias ?? {}),
// Wallet SDKs are intentionally NOT aliased to `false`.
// They are lazy-loaded via dynamic imports in useWalletConnector.ts
// and the wallet connector modules under src/lib/walletConnectors/.
// Setting them to `false` breaks wagmi connector detection and
// prevents WalletConnect v2, Safe, Coinbase, and MetaMask connections.
};
if (!isServer && config.optimization?.splitChunks) {
config.optimization.splitChunks = {
...config.optimization.splitChunks,
cacheGroups: {
...(config.optimization.splitChunks.cacheGroups ?? {}),
web3: {
name: "web3-vendors",
test: /[\\/]node_modules[\\/](wagmi|viem|ethers|@walletconnect|@metamask|@coinbase)[\\/]/,
chunks: "all",
priority: 35,
},
charts: {
name: "chart-vendors",
test: /[\\/]node_modules[\\/](recharts|d3-.*)[\\/]/,
chunks: "all",
priority: 25,
},
safe: {
name: "safe-vendors",
test: /[\\/]node_modules[\\/]@safe-global[\\/]/,
chunks: "all",
priority: 30,
},
},
};
}
if (isAnalyzeEnabled && !isServer && !isProd) {
class BuildStatsPlugin {
apply(compiler: any) {
compiler.hooks.done.tap("BuildStatsPlugin", (stats: any) => {
const fs = require("fs");
const path = require("path");
const outputPath = path.join(
compiler.options.output.path ?? ".next",
"build-stats.json",
);
fs.writeFileSync(
outputPath,
JSON.stringify(
stats.toJson({
all: false,
assets: true,
chunks: true,
chunkGroups: true,
}),
null,
2,
),
);
});
}
}
config.plugins.push(new BuildStatsPlugin());
}
return config;
},
};
export default nextConfig;