-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnext.config.mjs
More file actions
98 lines (87 loc) · 3.59 KB
/
next.config.mjs
File metadata and controls
98 lines (87 loc) · 3.59 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
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const emptyModulePath = path.resolve(__dirname, 'src/lib/empty-module.ts');
const emptyModuleAlias = './src/lib/empty-module.ts';
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
typedRoutes: false,
transpilePackages: ['@shared'],
typescript: {
ignoreBuildErrors: true,
},
// ─── Experimental ────────────────────────────────────────────────────────────
experimental: {
workerThreads: true,
// Tree-shake large icon libraries at import time
optimizePackageImports: [
'lucide-react',
'date-fns',
'recharts',
'framer-motion',
],
},
// ─── Images ──────────────────────────────────────────────────────────────────
images: {
remotePatterns: [
{ protocol: 'https', hostname: 'res.cloudinary.com' },
{ protocol: 'https', hostname: 'upload.wikimedia.org' },
{ protocol: 'https', hostname: 'images.unsplash.com' },
],
unoptimized: false,
},
// ─── Turbopack alias (dev) ────────────────────────────────────────────────────
turbopack: {
root: __dirname,
resolveAlias: {
canvas: emptyModuleAlias,
fs: emptyModuleAlias,
net: emptyModuleAlias,
tls: emptyModuleAlias,
},
},
// ─── Webpack alias (build / test) ────────────────────────────────────────────
webpack(config) {
config.resolve = config.resolve ?? {};
config.resolve.alias = {
...(config.resolve.alias ?? {}),
canvas: emptyModulePath,
fs: emptyModulePath,
net: emptyModulePath,
tls: emptyModulePath,
};
config.resolve.fallback = {
...(config.resolve.fallback ?? {}),
fs: false,
net: false,
tls: false,
};
return config;
},
// ─── Keep native packages server-side only ───────────────────────────────────
serverExternalPackages: ['canvas'],
// ─── Page extensions ─────────────────────────────────────────────────────────
pageExtensions: ['tsx', 'ts', 'jsx', 'js'],
// ─── API Proxy ───────────────────────────────────────────────────────────────
// All client-side calls to /api/* are forwarded to the NestJS backend.
// SSR calls use INTERNAL_API_URL (localhost:8000) directly for speed.
async rewrites() {
const configuredTarget =
process.env.INTERNAL_API_URL ??
process.env.NEXT_PUBLIC_API_URL ??
'http://localhost:8000/api';
const normalizedTarget = configuredTarget.replace(/\/$/, '');
const apiTarget = normalizedTarget.endsWith('/api')
? normalizedTarget
: `${normalizedTarget}/api`;
return [
{
source: '/api/:path*',
destination: `${apiTarget}/:path*`,
},
];
},
};
export default nextConfig;