Repository navigation
Expand file tree
/
Copy pathnext.config.ts
More file actions
166 lines (159 loc) · 4.94 KB
/
Copy pathnext.config.ts
File metadata and controls
166 lines (159 loc) · 4.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
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
import type { NextConfig } from "next";
import createNextIntlPlugin from "next-intl/plugin";
import withBundleAnalyzer from "@next/bundle-analyzer";
import withPWA from "@ducanh2912/next-pwa";
const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts");
const analyzer = withBundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
});
/**
* Code splitting strategy (#1136)
*
* Heavy chart/analytics components (recharts, framer-motion, NetworkGraph, etc.)
* are loaded on-demand via Next.js dynamic() in:
* src/components/dynamic-imports.ts
*
* This keeps them out of the initial JS bundle, reducing Time-to-Interactive.
* `optimizePackageImports` below enables tree-shaking for the same libraries
* at the module level as a complementary optimisation.
*
* To analyse bundle sizes after a build:
* ANALYZE=true npm run build
*/
/**
* Security headers applied to every route via next.config.ts.
* The middleware (src/middleware.ts) also sets these at runtime so they are
* present on both static and dynamic responses.
*
* `upgrade-insecure-requests` is omitted here because next.config.ts headers
* run in all environments; the middleware applies it in production only.
*/
const securityHeaders = [
{
key: "Content-Security-Policy",
value: [
"default-src 'self'",
// 'unsafe-eval' is dev-only: Turbopack/React Fast Refresh use eval()
// to reconstruct stack traces across module boundaries. React never
// calls eval() in production, so the production CSP stays strict.
`script-src 'self' 'unsafe-inline'${process.env.NODE_ENV === "development" ? " 'unsafe-eval'" : ""}`,
"style-src 'self' 'unsafe-inline'",
"img-src 'self' data: blob: https://*.stellar.org",
"font-src 'self'",
"connect-src 'self' wss: https: https://*.sentry.io",
"frame-src 'none'",
"frame-ancestors 'none'",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self'",
].join("; "),
},
{ key: "X-Frame-Options", value: "DENY" },
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
{
key: "Permissions-Policy",
value: "camera=(), microphone=(), geolocation=()",
},
];
const nextConfig: NextConfig = {
typescript: {
ignoreBuildErrors: true,
},
compress: true,
async headers() {
return [
{
source: "/(.*)",
headers: securityHeaders,
},
];
},
experimental: {
optimizePackageImports: [
"lucide-react",
"recharts",
"framer-motion",
"@stellar/stellar-sdk",
"d3-force-3d",
"react-force-graph-2d",
],
},
images: {
formats: ['image/webp', 'image/avif'],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
minimumCacheTTL: 2592000,
qualities: [50, 75, 85, 95],
remotePatterns: [
{
protocol: 'https',
hostname: '**.stellar.org',
},
],
},
webpack: (config, { isServer }) => {
if (!isServer) {
// Performance budgets — raw sizes (pre-gzip).
// 500 KB raw ≈ ~200 KB gzipped, matching the documented budget.
// In CI (process.env.CI=true) violations are errors; locally they are warnings.
config.performance = {
hints: process.env.CI ? 'error' : 'warning',
maxAssetSize: 500 * 1024, // 500 KB per asset
maxEntrypointSize: 500 * 1024, // 500 KB per entrypoint
};
config.optimization = {
...config.optimization,
splitChunks: {
chunks: 'all',
cacheGroups: {
default: false,
vendors: false,
vendor: {
filename: 'chunks/vendor.js',
test: /node_modules/,
priority: 10,
reuseExistingChunk: true,
name: 'vendor',
},
charts: {
filename: 'chunks/charts.js',
test: /[\\/]node_modules[\\/](recharts|d3-force-3d|react-force-graph-2d)[\\/]/,
priority: 20,
reuseExistingChunk: true,
name: 'charts',
},
animation: {
filename: 'chunks/animation.js',
test: /[\\/]node_modules[\\/](framer-motion)[\\/]/,
priority: 20,
reuseExistingChunk: true,
name: 'animation',
},
common: {
filename: 'chunks/common.js',
minChunks: 2,
priority: 5,
reuseExistingChunk: true,
name: 'common',
},
},
},
};
}
return config;
},
};
export default analyzer(withNextIntl(withPWA({
dest: "public",
cacheOnFrontEndNav: true,
aggressiveFrontEndNavCaching: true,
reloadOnOnline: true,
disable: process.env.NODE_ENV === "development",
fallbacks: {
document: "/offline",
},
workboxOptions: {
disableDevLogs: true,
},
})(nextConfig)));